Page 1 of 1
Flip Sprite
Posted: Sun Feb 21, 2021 11:51 am
by Cristof
Hello
Is there a easy way to flip/scale sprite in dialogue so it looks like character is turning to speaker?
Re: Flip Sprite
Posted: Sun Feb 21, 2021 1:24 pm
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.