I Changed the movement of my character to move with WASD, when setting the animator float i don’t know what to pass in, if I use “speed” the animator set him to run and he doesn’t stop, the “direction.magnitude” he stays idle. I really don’t want to use “set bool” lol, trying to keep the float because of the blend tree animations.
void Update()
{
tpnavMeshAgent = GetComponent<NavMeshAgent>();
tpanimator = GetComponent<Animator>();
Move(direction);
}
public void Move(Vector3 direction)
{
if (tpcanMove == false) return;
if (direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnspeedTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
tpnavMeshAgent.Move(moveDir.normalized * speed * Time.deltaTime);
UpdateAmimator();
}
}
void UpdateAmimator()
{
tpanimator.SetFloat("Forward", direction.magnitude, .1f, Time.deltaTime);
}