GameObjects rotation
Hey folks, I am making a 2D game in which there are obstacles (like birds) moving on the X-Axis from the left to the right or viceversa and are prefabs. They have a moving speed . I've put a collider which instantiates a random Obstacle in his position when OnTriggerEnter2D() is true. Now, this instantiator has an Array of Obstacles and all of them are facing to the right, so their moving speed is positive. If I want to instantiate a random obstacle facing to the left I (obviously) use the instantiate function giving it as a parameter the angle of the obstacle facing the right + 180 degrees. So far so good but if I try to change the speed to a negative value , so the object will move to the left and not to the right, it seems to be changing the speed of the original obstacle in the array which was facing to the right. So the next time I try to instantiate a new obstacle facing the right its speed is negative ... and this is a problem. Any ideas on how to acomplish this ? And nope,I don't have the script . I got angry and deleted it sorry .
I think you should rather change the transform.localScale to (-1, -1 , -1) ins$$anonymous$$d of rotating it 180 degrees
first of all, you shouldn't ever delete your scripts if you are still working on them. This not only makes it harder for people to help you, but you may want to go back and revise things or even copy and paste some parts, secondly, you can always set the speed on an object in a direction based on its transform so you can do something like:
this.transform.position = this.transform.position + this.transform.forward * speed;
that will always move the object in the direction it is facing regardless of its rotation. (use vector3.lerp or vector2.lerp to smooth out the movement)