Flip Sprite

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Cristof
Posts: 2
Joined: Tue Dec 29, 2020 3:43 am

Flip Sprite

Post by Cristof »

Hello
Is there a easy way to flip/scale sprite in dialogue so it looks like character is turning to speaker?
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Flip Sprite

Post by Tony Li »

Hi,

You can add a script with an OnConversationStart method to the character.

The implementation may depend on the specifics of your game. For example, say that your characters use a SpriteRenderer with a sprite that by default faces right. To face left, you set the SpriteRenderer's Flip X bool to true. Then your script's OnConversationStart method could look like:

Code: Select all

void OnConversationStart(Transform other)
{
    if (other != null && other != this.transform)
    {
        GetComponent<SpriteRenderer>().flipX = other.transform.position.x < this.transform.position.x;
        
    }    
}
You could do something similar if you make characters change direction by setting transform.localScale.x, or by setting the transform's Y rotation to 0 for right or 180 for left, etc.

If your characters have turn animations, you might want to get fancier and make the character play a turn animation. It's up to you.
Post Reply