Hi. I have a sprite sheet for an overhead/top down motorcycle game:
I want to choose which of the 8 angles to use based on the direction the player was last moving in. Does anyone know if this is possible?
Hi. I have a sprite sheet for an overhead/top down motorcycle game:
I want to choose which of the 8 angles to use based on the direction the player was last moving in. Does anyone know if this is possible?
First of all, you’ll have to use something in the Animator
called a Blend Tree
“Unity - Manual: Blend Trees”.
You can use this code for getting the player’s input (if you’re using the Old Input System):
//Reference to players animator
public Animator anim;
//The direction axis where the player is gonna move
float horizontal;
float vertical;
void Update()
{
//Getting the players input
horizontal = Input.GetAxisRaw("Horizontal");
vertical = Input.GetAxisRaw("Vertical");
//Setting the animators parameters
anim.SetFloat("X", horizontal);
anim.SetFloat("Y", vertical);
}
That’s the code, let’s move to the Animator Window
:
This is how it’s supposed to look
And here are al the values you have to set, in the Motion Parameter
you have to put the animation that is going to play depending on what direction is looking.
If you don’t quite understand how to do it. I would recommend watching a youtube video from “Brackeys”, that explains how to do a Top Down Movement and the Animation: TOP DOWN MOVEMENT in Unity! - YouTube (He only uses 4-Direction Movement, but it’s kinda simple to learn so you can add the other 4 Directions later).
Hope this helps