Problem rotating spheres around empty parent

I am working on a 2d sidescrolling game.

I am trying to implement a “shield” for the player’s ship made up of 4 spheres. These 4 spheres are set as children of an empty parent object I have attached to my ship. My goal is to have them spin around the player ship’s Z axis.

I figured I could create the empty parent and set it on my ship’s center, add the 4 spheres to the empty object as children, zero out their locations and then move them in their respective directions to achieve a north south east west orientation of 4 spheres spaced 3 units away from the center. I then created a script and attached it to the empty parent object which would rotate the parent 10 degrees a second.

Here is my script, very simple but maybe I’m using rotate wrong. I will explain below.

#pragma strict
var myShieldTransform : Transform;

function Start () {
	myShieldTransform = gameObject.transform;
}

function Update () {
	//Rotate the object around its Z axis at 10 degree/second.
    myShieldTransform.Rotate(0, 0, (10 * Time.deltaTime));

}

The script will rotate all 4 spheres as I expected, however, they become skewed compared to their original orientation while moving around. I’m kind of stumped as to why. I have tried making sure my ship, empty parent, and all spheres are at 0 in the Z axis. The sphere size and scale does not change while running, but the collider’s green wireframe does not stay consistent with the sphere’s borders. I have attached an image to clarify.

Image on IMGur

Thank you for any help. I don’t want to proceed until I figure this out. When I fully implement this the shield not having matching colliders will look funny when deflecting enemy fire.

You said it is a 2D game, if they are being skewed try to forcefully align it in the axis you are not using to keep it as much aligned as possible, if the problem persist then come back.

1 Answer

1

I like figuring out rotation problems, but from the information given, I cannot figure out how you are getting this behavior. Here is something to explore. Make the four spheres a child of the empty game object as you’ve done here, but don’t make it a child of the ship. Next an empty game object as a child of the ship at the pivot point. Now in the script above, have it track the pivot object. That is, your shield will follow the ship but it will not be a child of the ship. This may or may not fix the problem, but it will tell you something about the nature of the problem.