Hi, I’m doing a remake of the 2D Asteroids game. Currently, I did a single sprite(technically just strips of cubes put together through parenting) for all of my asteroids, so all of my asteroids look the same. To make it look a little more interesting, I decided to have a random rotation on their y-axis (my objects only move in the x and z axes as it’s 2D), every time it’s instantiated.
So in my asteroids script, I have something like this:
void Start () {
MyTransform.rotation = Quaternion.Euler(0.0f, Random.Range(0, 360), 0.0f);
rigidbody.AddForce(Random.insideUnitCircle * 200); //create random direction movement
}
So, I got what I wanted, they are now facing different directions upon instantiation. However, they no longer follow my wrapping script, which has the following code:
void Update () {
if(myTransform.position.x >= maxX){
myTransform.position = new Vector3(minX, myTransform.position.y, myTransform.position.z);
}
else if(myTransform.position.x <= minX){
myTransform.position = new Vector3(maxX, myTransform.position.y, myTransform.position.z);
}
else if(myTransform.position.z >= maxZ){
myTransform.position = new Vector3(myTransform.position.x, myTransform.position.y, minZ);
}
else if(myTransform.position.z <= minZ){
myTransform.position = new Vector3(myTransform.position.x, myTransform.position.y, maxZ);
}
}
I’m guessing this is because, I rotated its transform, therefore, I also rotated the object’s axes, whereas the world’s orientation remained untouched. Just a wild guess though.
Is there a way that I could probably solve this? It’s pretty much impossible to check wrapping for every angle there could possibly be, right?.
Thank you so much for your patience.