my script worked fine without walking animations but once i implemented them and used isMoving my player does not move forward and if i press down he goes up
ive also made sure that the transitions were correct from idle to walk walk to idle and that the values true , false for ismoving in the transitions are correct but i still dont know what to do
please help
this is for a pokemon style 2d game btw
this is the script i had and what i expect is for the player to move up down left right using the walking animations
void Update()
{
bool isMoving = false;
// Determine movement direction based on input
if (Input.GetKey(KeyCode.D))
{
moveDirectionX = 1f;
moveDirectionY = 0f;
isMoving = true;
animator.SetBool("isMoving", isMoving);
}
else if (Input.GetKey(KeyCode.A))
{
moveDirectionX = -1f;
moveDirectionY = 0f;
isMoving = true;
animator.SetBool("isMoving", isMoving);
}
else if (Input.GetKey(KeyCode.W))
{
moveDirectionX = 0f;
moveDirectionY = 1f;
isMoving = true;
animator.SetBool("isMoving", isMoving);
}
else if (Input.GetKey(KeyCode.S))
{
moveDirectionX = 0f;
moveDirectionY = -1f;
isMoving = true;
animator.SetBool("isMoving", isMoving);
}
// Move the player based on the determined direction
if (isMoving)
{
Vector3 moveDirection = new Vector3(moveDirectionX, moveDirectionY, 0f).normalized;
transform.Translate(moveDirection * speed * Time.deltaTime);
}
// Update animator parameters based on current movement status
animator.SetFloat("MoveX", moveDirectionX);
animator.SetFloat("MoveY", moveDirectionY);
animator.SetBool("isMoving", isMoving);
}
}
Mohamed Laraki Hossini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.