hi, i’m working on a directional animation system rn using the animator; i followed this tutorial to figure out how to get the directional part to work, and it’s working fine except for the fact that the upwards idle animation isn’t playing even after moving up - it just plays the downwards one instead. does anyone know how i can fix this?
here’s the code i’m using:
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovementAnimated : MonoBehaviour
{
[SerializeField] private MovementType2D mType;
[SerializeField] private float speed;
private Animator animator;
private Rigidbody2D rb;
private float xMovement = 0f;
private float yMovement = 0f;
// Awake = initialisations
private void Awake()
{
rb = gameObject.GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
private void OnMovementXY(InputValue value)
{
xMovement = value.Get<Vector2>().x;
yMovement = value.Get<Vector2>().y;
}
// FixedUpdate = input application
void FixedUpdate()
{
// Movement Script
Vector2 movement;
switch (mType)
{
case MovementType2D.xAxis:
movement = new Vector2(xMovement * speed * Time.deltaTime, rb.velocity.y);
break;
case MovementType2D.yAxis:
movement = new Vector2(rb.velocity.x, yMovement * speed * Time.deltaTime);
break;
default: // x&y axis movement
movement = new Vector2(xMovement * speed * Time.deltaTime, yMovement * speed * Time.deltaTime);
break;
}
rb.velocity = movement;
// Animate movement
ApplyAnim();
}
private void ApplyAnim()
{
animator.SetFloat("MovementX", xMovement);
animator.SetFloat("MovementY", yMovement);
// Get idle anim direction
if(xMovement >= 0.5f || xMovement <= -0.5f || yMovement >= 0.5f || yMovement <= -0.5f)
{
animator.SetFloat("LastMoveX", xMovement);
animator.SetFloat("LastMoveX", xMovement);
}
}
}
and my animator trees are pretty much identical to how they’re set up in the video i linked, just with different sprites - if there’s any specific information you guys need about it please let me know
thanks!