Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected virtual void OnAnimatorMove () {
- if (applyDefault)
- {
- anim.ApplyBuiltinRootMotion();
- return;
- }
- if (aiMovement == null)
- return;
- aiMovement.MovementUpdate(Time.deltaTime, out Vector3 nextPosition, out Quaternion nextRotation);
- //var desiredVelocity = (ai.steeringTarget - tr.position).normalized * 2;//ai.desiredVelocity;
- Vector3 desiredVelocity = aiMovement.desiredDirection * aiMovement.desiredVelocity.Flat().magnitude;
- Vector3 desiredVelocityWithoutGravity = desiredVelocity.Flat();
- // Calculate the desired velocity relative to the character (+Z = forward, +X = right)
- Vector3 localDesiredVelocity = aiTransform.InverseTransformDirection(desiredVelocityWithoutGravity);
- smoothedVelocity = Vector3.Lerp(smoothedVelocity, localDesiredVelocity, velocitySmoothing > 0 ? Time.deltaTime / velocitySmoothing : 1);
- anim.SetFloat(AnimFloat_Right, smoothedVelocity.x);
- anim.SetFloat(AnimFloat_Forward, smoothedVelocity.z);
- // Calculate how much the agent should rotate during this frame
- nextPosition = aiMovement.position;
- // Use gravity from the movement script, not from animation
- Vector3 deltaPos = anim.deltaPosition;
- deltaPos.y = aiMovement.desiredVelocity.y * Time.deltaTime;
- nextPosition += deltaPos;
- // Call the movement script to perform the final movement
- aiMovement.FinalizeMovement(nextPosition, nextRotation);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement