- Home /
2D example: Flip character without moving
Hi! I've sat down with the 2D example and I thought I would try to build a similar game like the example. I used to movement script and tried it all worked. Except one thing. When I call the Flip() function the character moves one unit, which I haven't seen in the example code provided by Unity. I've compared the code but didn't find any difference... It would be a huge help if you can tell me how I'd flip a character to face the other way without having the character to go a few units from where you flipped it.
void Flip ()
{
// Switch the way the player is labelled as facing.
facingRight = !facingRight;
Debug.Log (transform.localPosition);
// Multiply the player's x local scale by -1.
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
If you need anything else, just ask. And my character is an empty gameobject with more empty gameobjects with parts of the character and all colliders on the parent gameobject "character".
Thanks!
Your answer
Follow this Question
Related Questions
Flip 2D player in x-axis to face movement direction 5 Answers
How do I make my player flip to always face the enemy and vice versa? 1 Answer
Flip 2D Character with Keys without moving 2 Answers
2D Character Flip 2 Answers
Flip a 2d character 3 Answers