Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. protected virtual void OnAnimatorMove () {
  2.  
  3. if (applyDefault)
  4. {
  5. anim.ApplyBuiltinRootMotion();
  6. return;
  7. }
  8.  
  9. if (aiMovement == null)
  10. return;
  11.  
  12. aiMovement.MovementUpdate(Time.deltaTime, out Vector3 nextPosition, out Quaternion nextRotation);
  13.  
  14. //var desiredVelocity = (ai.steeringTarget - tr.position).normalized * 2;//ai.desiredVelocity;
  15. Vector3 desiredVelocity = aiMovement.desiredDirection * aiMovement.desiredVelocity.Flat().magnitude;
  16. Vector3 desiredVelocityWithoutGravity = desiredVelocity.Flat();
  17.  
  18. // Calculate the desired velocity relative to the character (+Z = forward, +X = right)
  19. Vector3 localDesiredVelocity = aiTransform.InverseTransformDirection(desiredVelocityWithoutGravity);
  20.  
  21. smoothedVelocity = Vector3.Lerp(smoothedVelocity, localDesiredVelocity, velocitySmoothing > 0 ? Time.deltaTime / velocitySmoothing : 1);
  22.  
  23. anim.SetFloat(AnimFloat_Right, smoothedVelocity.x);
  24. anim.SetFloat(AnimFloat_Forward, smoothedVelocity.z);
  25.  
  26. // Calculate how much the agent should rotate during this frame
  27. nextPosition = aiMovement.position;
  28.  
  29. // Use gravity from the movement script, not from animation
  30. Vector3 deltaPos = anim.deltaPosition;
  31. deltaPos.y = aiMovement.desiredVelocity.y * Time.deltaTime;
  32. nextPosition += deltaPos;
  33.  
  34. // Call the movement script to perform the final movement
  35. aiMovement.FinalizeMovement(nextPosition, nextRotation);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement