Question by
unity_wKFssLLhuqlIZQ · Apr 22, 2021 at 09:08 PM ·
animation2d gametopdown
how can i trigger a animation while moving in a 2d topdown game,How can i trigger movement animations in a 2d topdown game
Im making a topdown 2d game. And i have made a walking animation, im trying to trigger it when i move my character. I made a parameter called Moving and when im moving the parameter needs to be above 0 i tried online tutorials but their animation code doesnt match my movement code, This is my movement code.
public class Playermovement : MonoBehaviour { public Animator animator;
public float moveSpeed = 10f;
public Rigidbody2D rigidbody2D;
Vector2 movement;
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
rigidbody2D.velocity = movement * moveSpeed * Time.deltaTime;
}
},i'm making a 2d topdown game and i need my movement animation to trigger when you are moving i tried multiple tutorials but my movement code doesnt work with their animation code. When im walking the parameter called Moving needs to be higher than 0,0 this is my movement code. public class Playermovement : MonoBehaviour { public Animator animator;
public float moveSpeed = 10f;
public Rigidbody2D rigidbody2D;
Vector2 movement;
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
rigidbody2D.velocity = movement * moveSpeed * Time.deltaTime;
}
}
Comment