- Home /
Issue with Animations using WASD Movement in Isometric view
Hi,
I have an issue with playing movement animations in Unity, and syncing it to my character's rotation. The game that I currently have is an isometric view shooter, think Angry Bots, where the player is moved with the WASD keys and faces the mouse cursor. Right now, I have a basic system going where I am moving the player using transform.translate
on the world space, and using a simple LookAt on a raycasted point on where the mouse cursor is pointing.
Now, the issue is that I have a problem with coding the animations when the player moves. There is no issue when the player only presses a single button, but it messes up when the player presses 2 keys at once (e.g. left and up), because it doesn't know what animation to play. Is there any workaround to this method? My code is currently basically hardcoding the entire system and it's not working.
//WHEN MOVING UPWARDS
if (transform.rotation.y >= 315 || transform.rotation.y <= 45)
{
if (playerMoveScript.movingUp)
{
if (animationState != "Walk")
{
playerAnimator.Play("Walk");
}
}
if (playerMoveScript.movingDown)
{
if (animationState != "WalkBack")
{
playerAnimator.Play("WalkBack");
}
}
if (playerMoveScript.movingLeft)
{
if (animationState != "MoveLeft")
{
playerAnimator.Play("MoveLeft");
}
}
if (playerMoveScript.movingRight)
{
if (animationState != "MoveRight")
{
playerAnimator.Play("MoveRight");
}
}
}
This code is put in the update function, and works hand in hand with the movement script (if the left key is pressed, movingLeft will be set to true, etc.
Any help will be appreciated! Thanks!