Guest User

Untitled

a guest
Mar 30th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. /// <summary>
  2. /// This gets us an axis around which to spin, in the target bone's space, that is perpendicular to the direction of the incoming damage.
  3. /// We use it for jiggle calculations, spinning backflips, etc.
  4. /// </summary>
  5. /// <param name="damagingHit">the incoming hit/damage we want to be perpendicular to</param>
  6. /// <param name="targetBone">the bone (transform space) in which to generate the perp spin axis</param>
  7. /// <returns></returns>
  8. protected Vector3 GetPerpSpinAxis(HitboxFistState damagingHit, Transform targetBone)
  9. {
  10. // Get as precise an attacker origin as we can get.
  11. Vector3 damageOrigin = gameObject.transform.position;
  12. if (damagingHit.TargetFist != null)
  13. {
  14. Quaternion tempRot = Quaternion.identity; // (unused, since we don't care about a local orientation here)
  15. damagingHit.CalcRelativeHitboxTransforms(damagingHit.forceOffset, Quaternion.identity, ref damageOrigin, ref tempRot);
  16. }
  17. else if (damagingHit.parentObject != null)
  18. {
  19. // @TODO: Maybe make another version of this method that just lets us specify this, for getting a perp axis without incoming damage
  20. damageOrigin = damagingHit.parentObject.transform.position;
  21. }
  22.  
  23. // We want to generate a right-vector here, so that positive rotation is always "away" from attacker.
  24. Vector3 fromAttacker = targetBone.position - damageOrigin;
  25. fromAttacker.y = 0.0f;
  26. // (if we're too far above/below the attacker, we just default to our own right)
  27. Vector3 perpAxis = gameObject.transform.right;
  28. if (fromAttacker.magnitude > 0.1f)
  29. {
  30. perpAxis = Vector3.Cross(Vector3.up, fromAttacker.normalized);
  31. perpAxis = targetBone.worldToLocalMatrix * perpAxis;
  32. perpAxis.Normalize();
  33. }
  34.  
  35. return perpAxis;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment