Mirroring a gameObject
Hi!
I'm trying to mirror a 2D gameObject but all i can find is to flip it by reversing its localScale on the x axis. The problem I face is that I slightly rotate this game object during runtime facing up so at the moment I flip the gameObject it looks like it's facing down instead of up in the other way. Can't figure out how to mirror the game object without messing up the direction it's facing.This is what i'm doing at the moment.
//flip Tom
if (x > 0 && lastF == 0) {
transform.localScale = new Vector3 (-transform.localScale.x, transform.localScale.y, transform.localScale.z);
lastF = 1;
}
if (x < 0 && lastF == 1) {
transform.localScale = new Vector3 (transform.localScale.x, transform.localScale.y, transform.localScale.z);
lastF = 0;
}
EDIT: I can't flip the sprite as I need it to flip de collider aswell.
To my understanding, flipping in general, works by using the opposite value of the objects size, so if your object is 30x by 30y, and you wanted to flip it upside down, youd make it become 30x by -30y. Since its a sprite, the Flip bool values should do just that, though if im understanding your issue correctly, if the colliders are not flipping too (which the should), you could apply the same logic to flipping the colliders with the image, or simply flip the entire gameObject, rather than the sprite itself.
I thought so, but flipping in the y axis doesn't do anything, it should but it stays the same... That should solve the problem in my $$anonymous$$d but not in unity.