Guest User

Untitled

a guest
May 30th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. namespace SpartanFist
  5. {
  6. /// <summary>
  7. /// This is a twiddler that is activated by punching - but you MUST punch it from the front, while facing it, and the punch must come from some actual parent-object.
  8. /// </summary>
  9. public class TwiddlerPunchable : Twiddler
  10. {
  11. /// <summary>
  12. /// Indicates we've been hit by something, and should probably be offended
  13. /// </summary>
  14. /// <param name="hitState">the stats wot hit us</param>
  15. public void FistHit(HitboxFistState hitState)
  16. {
  17. if (hitState.parentObject == null) { return; } // (it takes an actual person to hit us)
  18.  
  19. float headingDot = Vector3.Dot(hitState.parentObject.transform.forward, gameObject.transform.forward);
  20. if (headingDot > 0.0f) { return; } // ... and they have to be facing us...
  21.  
  22. headingDot = Vector3.Dot(hitState.parentObject.transform.position - gameObject.transform.position, gameObject.transform.forward);
  23. if (headingDot < 0.0f) { return; } // ... and they ALSO need to be in front of us, not hitting from the side or rear.
  24.  
  25. // Otherwise, cool, we got punched! So we twiddle...
  26. bool hitRegistered = Twiddle(!toTwiddle.SwitchState);
  27.  
  28. // ... and we let the hitter know if they successfully hit something. If we can't twiddle in that direction, they should probably get a <TANG!> kind of hit like they would if they hit an armored guy.
  29. hitState.HitResponse(this.gameObject, hitRegistered ? -1.0f : 0.0f);
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment