0
\$\begingroup\$

So far I know of the following ways to turn a 2D character to face the other direction (in my case the char can only walk left or right):

  1. Mirror the right walk animation and use that as a separate state in the animation controller.

  2. Simply set a 180 rotation on the game object that hold all of my characters parts when he turns the other way.

  3. Create a transition animation by blending (I don't know if it's called exactly like this) the left oriented sprite and the right one.

  4. Orient the sprite based on its movement direction using this code:

    void OrientChar()
    {
        Vector3 moveDirection = gameObject.transform.position - _origPos;
        if(moveDirection != Vector3.zero)
        {
            float angle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg;
            gameObject.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        }
    }
    

1 and 2 will create a rather abrupt change and might not look smooth. How do I make them or is it possible to make them smooth?

For number 3 I have a very basic idea on how to do it. Can I do it directly Unity?

\$\endgroup\$
  • \$\begingroup\$ Are you asking for the best option? Because we can't know that. You might want to work on the scope or focus of your question. \$\endgroup\$ – Kirbinator Apr 20 '16 at 21:46
  • \$\begingroup\$ I'm mainly asking for people to share the solutions that have worked for them, so I can make a more informed decision. \$\endgroup\$ – Uri Popov Apr 21 '16 at 7:07
  • \$\begingroup\$ I am guessing the Flip X option in the sprite renderer isn't good enough? answers.unity3d.com/questions/952558/… \$\endgroup\$ – Evgeny Vasilyev May 5 '17 at 21:10
1
\$\begingroup\$

The best way to rotate a 2D character is to change the localScale from 1 to -1. This will allow you to place normal maps and have dynamic lighting affect your character. You shouldn't rotate your character while using a 2D character unless you want the paper-ish, textbook affect.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.