Hey i am working in 2D and im trying to make it so when my character moves diagonal their animation is moving the same speed as if they were going straight in one other direction. I even Normalize d the movement
public float moveSpeed = 2.5f;
public Rigidbody2D rb;
Vector2 movement;
public Animator animator;
private float xmove = 0f;
private float ymove = 0f;
private float move = 0f;
private void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
xmove = movement.x;
ymove = movement.y;
move = xmove + ymove;
//if (Math.Abs(xmove) == Math.Abs(ymove))
//{
// moveSpeed = 1.75f;
// }
// else
// {
// moveSpeed = 2.5f;
//}
movement.Normalize();
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
if (Input.GetKey(KeyCode.LeftShift))
{
moveSpeed = 4.5f;
print("Running");
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
print("Not Running");
moveSpeed = 2.5f;
}
}
private void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
//
//print(xmove.ToString()+' '+ ymove.ToString());
}