I have a 2D freeform directional blend tree, have horizontal and Vertical float values inserted. I just want them to be updated automatically when my character moves, I'm not moving the character using keyboard or Mouse I'm merely setting Destination for the character to go to
Asked
Active
Viewed 744 times
1 Answers
0
Just save last position and check direction every frame. For example:
public class AnimationDemo : MonoBehaviour
{
private Vector3 _lastPosition;
private void Awake()
{
_lastPosition = gameObject.transform.position;
}
private void Update()
{
var currentPosition = gameObject.transform.position;
var moveDirection = currentPosition - _lastPosition;
CalculateAnimation(moveDirection);
_lastPosition = currentPosition;
}
private void CalculateAnimation(Vector3 moveDirection)
{
//you have moveDirection to send in your animation system
}
}

Red-Cat-Fat
- 54
- 1
- 6
-
That is the moving direction. Combine that with the look-direction (`transform.forward`). Use [Vector3.Dot](https://docs.unity3d.com/ScriptReference/Vector3.Dot.html) to calculate the sideways movement factor. And maybe [SignedAngle](https://docs.unity3d.com/ScriptReference/Vector3.SignedAngle.html) to get the sideways direction (left or right). Then, play with the NavMeshAgent's turn speed. – KYL3R Jun 01 '21 at 10:43