Guest User

Untitled

a guest
Mar 30th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. void LateUpdate()
  2. {
  3. int curBaseAnimHash = GetCurAnim();
  4. if (curBaseAnimHash == impactHash)
  5. {
  6. float flinchRemaining = 0.0f;
  7. float flinchTotalTime = 0.0f;
  8. ai.GetVariable(NpcVars.FlinchRemaining, out flinchRemaining);
  9. ai.GetVariable(NpcVars.FlinchTotalTime, out flinchTotalTime);
  10.  
  11. if (MathManager.IsNearZero(flinchRemaining)) { jiggleBone.localRotation = jiggleBoneRot; }
  12. else
  13. {
  14. // First, do a proper, actual spring equation (even if we're poking in garbage magical tweak params instead of actual mass/etc)
  15. float jiggleAngle = Mathf.Exp(-sproingDampening * (flinchTotalTime - flinchRemaining)) * sproingAngle * ((Mathf.Cos((flinchTotalTime - flinchRemaining) * sproingFactor * Mathf.PI + Mathf.PI) + 1.0f) * 0.5f);
  16.  
  17. // Now just taper the fucker. That way it doesn't give a shit. Underdampen it to hell and back. We still staple on a nice taper, so it "just works" and you can make it pretty.
  18. float taperFactor = (flinchTotalTime - flinchRemaining) / flinchTotalTime;
  19. taperFactor *= taperFactor;
  20. taperFactor = 1.0f - taperFactor;
  21.  
  22. jiggleAngle *= taperFactor;
  23.  
  24. // Then, apply the tapered angle. Tadaaaaa!
  25. jiggleBone.localRotation = jiggleBoneRot * Quaternion.AngleAxis(jiggleAngle, jiggleAxis);
  26. }
  27. }
  28. else if (curBaseAnimHash == launchHash)
  29. {
  30. float flinchRemaining = 0.0f;
  31. float flinchTotalTime = 0.0f;
  32. ai.GetVariable(NpcVars.FlinchRemaining, out flinchRemaining);
  33. ai.GetVariable(NpcVars.FlinchTotalTime, out flinchTotalTime);
  34.  
  35. if (MathManager.IsNearZero(flinchRemaining)) { spinBone.localRotation = spinBoneRot; }
  36. else
  37. {
  38. float totalSpinRads = Mathf.Round(flinchTotalTime * launchSpinsPerSec) * 360.0f;
  39. float spinTval = (flinchTotalTime - flinchRemaining) / flinchTotalTime;
  40.  
  41. // Then, apply the tapered angle. Tadaaaaa!
  42. spinBone.localRotation = spinBoneRot * Quaternion.AngleAxis(spinTval * totalSpinRads, spinAxis);
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment