0
\$\begingroup\$

I have a character that can move left and right.

Whenever it changes direction the character's localscale x is multiplied by -1.

The code looks like this:

private void Flip()
    {
        // Switch the way the player is labelled as facing.
        m_FacingRight = !m_FacingRight;

        // Multiply the player's x local scale by -1.
        Vector3 theScale = transform.localScale;
        theScale.x *= -1;
        transform.localScale = theScale;
    }

When it flips all children flip aswel. The character has a sprite child (a white bubble), which in turn has a Text Mesh Pro child.

This is the hierarchy:

enter image description here

And this is the result:

https://media.giphy.com/media/0H0rGKsksURbDcRqvo/giphy.gif

Is there a way to prevent the text from flipping on x?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I'd recommend setting up your character like this:

  • Root character object (with character control script, rigidbody, etc)
    • Character collision object (contains collider(s))
    • Character visual object (contains sprite renderer(s), animator, etc)
    • Text bubble object (contains white circle and text)

When you flip your character, flip only the "visual" child object, leaving the physics representation, text, and root object unchanged.

This structure gives you a lot of freedom to play with the visual object - like adding dynamic squash & stretch - without impacting legibility or gameplay logic.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .