Hey All,
Fairly new to unity and animation in general. I’m tyring to make an 8 directional player controller similar to Enter the Gungeon where the player object rotates and displays the idle sprite and walking animations based on the location of the mouse (Animation is triggered by movement but the direction of the movement does not change the direction the player is facing)
Im trying to get my character to transition between idle states when he is not moving but the mouse is, and change to walking animations when he and the mouse are both moving.
Im running into an issue where certain walking animations dont switch to idle when the player stops even though Ive set a transition to move to idle when his speed is 0.
Attached is a gif of the issue. The walking animation continues until my mouse hits the relative “1” value on the horizontal axis. The same thing happens for vertical.
Below is the blend tree setup to detect my mouse position to transition between the 8 directions. This works fine for movement and only causes an issue when I stop (Only using 4 directional idle sprites)
Here is an example of the transition I have setup to move to idle. Please excuse what I can only imagine is a messy animator.
Here is my player controller script. Any advice would be greatly appreciated!
public class Player2Movement : MonoBehaviour
{
public float moveSpeed = 5f;
public Rigidbody2D rb;
public Camera cam;
public Animator animator;
Vector2 movement;
Vector2 mousePos;
Vector2 posDif;
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
posDif = mousePos - rb.position;
animator.SetFloat("Horizontal", posDif.x);
animator.SetFloat("Vertical", posDif.y);
//animator.SetFloat("Horizontal", movement.x);
//animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
}