- Home /
How to invert a 2D animation
Hello Unity Community!
I'm almost started to learning Unity. I'm making a basic 2D game and I have a problem with animations. I have done all scripting and animations for basic movements (idle, walk, jump) but when I walk backward it's still playing the walk forward animation.
What should I do? I know it's a stupid question but I have tried to scale x -1 on local parameters but it doesn't work, the player (gameobject) appears on other x position.
I need a solution to fix this. Can somebody help me? Thanks you
var speed : float;
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.D)){
transform.position += Vector3.right * speed;
}
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.A)){
transform.position -= Vector3.right * speed;
You should multiply by Time.deltaTime to get an even speed across all framerates.
transform.position -= Vector3.right * speed * Time.deltaTime;
Answer by RayJr · Oct 15, 2014 at 05:30 PM
You can try this. Its working for me to reverse my sprites running annimation when he turns the other way.. Its' from this video. He explains how it works around the 42 minute mark.
https://unity3d.com/learn/tutorials/modules/beginner/2d/2d-controllers
void flip ()
{
facingright = !facingright;
Vector3 theScale = transform.localScale;
theScale.x *- = 1;
transform.localScale = TheScale;
}
Your answer
Follow this Question
Related Questions
Multiple Sprite animations 1 Answer
How do you create moving 2d effects? 1 Answer
Isit Possible to turn a drawing into sprite? 3 Answers
Using animated transform to push object away? 2D 0 Answers
Animated Tile control 0 Answers