- Home /
Player direction/idle animation
So I'm trying to make animations for a player. I already have the moving animation for 4 directions and idle animation for 4 directions. I'm using the animator and transition bars to do this. However, I realize this will probably take like 56 transition bars and that sounds super inefficient.
What I want to accomplish is that: if player walks left and then stops, then player switches from leftWalk to leftIdle. if player walks left, then walks right, then stops, then the player switches from leftWalk to walkRight, then idleRight.
the player moves accordingly if wasd or left,right,up,down key is pressed and when none of the keys are pressed, the player faces the direction it was previously walking toward (idleDirection).
I have 3 int parameters, walkDirection, idleDirection, and previousDirection(for storing the previous int value of walkDirection and set it equal to the idleDirection).
Speed is not an issue atm.
Answer by Kleiss · Jul 07, 2017 at 01:38 PM
3 year old, but i'll answer anyway. here is the pseudocode
//outside of function
Vector2 lastVector;
void function {
if ( player has input )
{
store player velocity in lastVector
}
animator.setfloat (lastvector.x)
animator.setfloat (lastvector.y)
}
this way your velocity will be stored as long as the player move the character.
the lastvector will keep the final values of the input. use it to switch your idle animation direction in your animation tree.
Thanks for explaining this. What is an actual code example of "store player velocity in lastVector"? I'm new and having trouble figuring out what to use to store new values. Thanks!
Answer by Baste · Oct 24, 2014 at 09:26 AM
I'm assuming that you're using sprites, since otherwise having separate animations for walking left and right makes no sense. If you're in a 3D world, just rotate your character, and use the two animations.
What you want with sprites is blend trees for each direction. Set up your tree with four blend trees: right/left/up/down, and set up transitions between them based on the direction you're moving in.
Within the trees, add the corresponding walk and idle animations. Blend based on the speed of the character, and set the threshold to be discrete - that is, either idle or walk, no in-between.
Your answer
Follow this Question
Related Questions
How to move player after animation 2 Answers
Character faces wrong way for one frame only. Why? 1 Answer
Player not moving 1 Answer
How can I add Animation to this player movement script? or do I have to create a totally new one? 0 Answers
How to get animation to Stop and Start with a key press 1 Answer