Sorry guys im I noob and unity. I need to make it so my character does a “turn left” animation when I press the “a” key and a “turn right” animation when I press the “d” key. how would I go about doing that? Thanks in advance for your help!
Check out the Character Animation tutorials in the Unity web page.
There’s one of a soldier that accomplishes what you need.
I checked that soldier tutorial out but it doesn’t seem like the soldier has any type of animation when he’s turning around in place. I need something that teaches me how to make it so if my character isn’t moving and just turns either left or right it does the respective animation.
Oh! I see…
I don’t know if there’s a tutorial for that.
But you have to use the same technique as when you move forward, but just check if the player speed is below a threshold you specify. If it’s below that threshold, then you assume the player is rotating in the same spot and run the animation.
As to which animation (right/left) to run, it’s easily verified with the key the player is pressing.
I hope this helps!
It will depend on exactly how you are handling the animation, but the code will look something like:-
var turnSpeed: float; // Degrees per second.
function Update() {
var turn = Input.GetAxis("Horizontal");
if (turn > 0) {
animation.CrossFade("RightTurn");
} else if (turn < 0) {
animation.CrossFade("LeftTurn");
}
transform.Rotate(turn * turnSpeed * Time.deltaTime);
}
Thanks! this is exactly what I needed!