Guest User

Untitled

a guest
Jul 27th, 2017
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. if (curBaseAnimHash == impactHash)
  2. {
  3. float flinchRemaining = 0.0f;
  4. float flinchTotalTime = 0.0f;
  5. ai.GetVariable(NpcVars.FlinchRemaining, out flinchRemaining);
  6. ai.GetVariable(NpcVars.FlinchTotalTime, out flinchTotalTime);
  7.  
  8. if (MathManager.IsNearZero(flinchRemaining)) { jiggleBone.localRotation = jiggleBoneRot; }
  9. else
  10. {
  11. // First, do a proper, actual spring equation (even if we're poking in garbage magical tweak params instead of actual mass/etc)
  12. float jiggleAngle = Mathf.Exp(-sproingDampening * (flinchTotalTime - flinchRemaining)) * sproingAngle * ((Mathf.Cos((flinchTotalTime - flinchRemaining) * sproingFactor * Mathf.PI + Mathf.PI) + 1.0f) * 0.5f);
  13.  
  14. // 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.
  15. float taperFactor = (flinchTotalTime - flinchRemaining) / flinchTotalTime;
  16. taperFactor *= taperFactor;
  17. taperFactor = 1.0f - taperFactor;
  18.  
  19. jiggleAngle *= taperFactor;
  20.  
  21. // Then, apply the tapered angle. Tadaaaaa!
  22. jiggleBone.localRotation = jiggleBoneRot * Quaternion.AngleAxis(jiggleAngle, jiggleAxis);
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment