Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly flip 2D character with new Unity4.3 2D framework? (Rotation of gameobjects during animation)

i'm already checked official Unity 4.3 example project, and there they use

Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;

This works pretty well, but. But i'm encountered an trouble, not sure this trouble with this Flip or with something else.

I'm use Animator to animate my characters, i have Attack animation, which in addition to the sprite animation also move character's Hand, which can carry the Weapon. Problem is when i flip the character to opposite direction Hand will move wrong (not as planned), which is wrong. (video below will be more descriptive)

I discovered that this problem occure only if i modify the Hand's rotation in animation, so if i works only with .position this works well, but i need the rotation!

What is best way to get this work?

Here the youtube video: http://youtu.be/qpMK2gRgDz8

At video i show animation without rotation uses, hand moves correct. But next i show it with rotation, as you can see when character turned right this works well, but when left, its completely wrong.

like image 981
Ignatii Marine Avatar asked Jan 26 '26 03:01

Ignatii Marine


1 Answers

What you want to do cannot be done with scaling cause scaling does not change the rotation of the object and so the forward vector remains the same. You must create double sided objects and just rorate them 180 degrees or you can ue a shader that draws a polygon even when its normal vector is against the camera.

like image 53
Alexandros Mouzakidis Avatar answered Jan 27 '26 18:01

Alexandros Mouzakidis