Im creating an enemy in my game, that follows the player when the player enters a trigger placed on the enemy gameobject, that checks for the player, all is well, the walking cycles work, but when the player leaves the trigger zone, the enemy dosent transition to its idle state. Am i missing something in my code? I’ve made sure that the transition is made whenever “isWalking” is true/false
void Movement()
{
direction = (target.position - transform.position).normalized;
transform.position = Vector2.MoveTowards(rb.position, player.rb.position, speed * Time.deltaTime);
if(followPlayer == true)
{
animator.SetFloat("MovementX", direction.x);
animator.SetFloat("MovementY", direction.y);
animator.SetBool("isMoving", true);
}
else
{
animator.SetBool("isMoving", false);
}
}