Issues with rotation

I have been looking everywhere and cannot find a reason for what is happening so I need some help. I have a parent object called “room” consisting of four children objects which are just flat cubes used to make a basic room. Now I want to whole “room” to rotate around it’s x axis (red in the picture) which shoots right through the middle of the whole room. Here is a link to see the setup:


However, when I use transform.Rotate(Speed,0,0) it rotates the room around what appears to be the x axis of the floor, not the x axis of the whole room.

Any help would be greatly appreciated.
Thank you,
Justin

Are you sure the ‘rotate’ script is attached to the right object? Can you post the script?

Yes it is attached to the parent object “room”.
The code is pretty simple.

var rSpd : int=30;

function Update () {



    if(Input.GetKey("e")){
    transform.Rotate(-rSpd*Time.deltaTime,0,0);
    }
    else if(Input.GetKey("q")){
     transform.Rotate(rSpd*Time.deltaTime,0,0);
    }

}

I’d suggest you look at where the pivot point of the room object really is. If it’s a model where it’s middle-bottom is 0,0,0 for it, then it would rotate around the floor.

Is the pivot point where the object’s axes appear when the object is selected in the hierarchy?

It is either the pivot or the center of the game object, depending on whether your settings is set on (check right at the right of tools Pan/Translate/Rotate/Scale).

Aha! I see when I changed it from center to pivot, that it moved the axis down to the bottom of the room. So knowing this is there a way to move the pivot point to the center of the object?
Thank you by the way.

It is possible, by using your modeling application (3DS Max…) :slight_smile:

Well here are my issues with that. I wanted to just use basic cubes in unity to create the walls,floor, etc. So that I could use cube colliders to keep it simple instead of a mesh collider for the whole room. So if I created the room (in C4D in my case), then import it, I would loose being able to use the cube colliders for each part of the room correct?
This was supposed to be the simple part of this project :\ haha

The easiest way to handle this, would be to attach the room to an empty gameobject, and put the room in the center of the gameobject. Then, apply the rotation to the gameobject, rather than the room model itself.

Of course, this masks the symptom, and doesn’t fix the problem.

Thank you much sir. It worked for now. I am not experienced enough to see exactly where this may come back to bite my in the butt. So for now I will just keep my finger’s crossed that it continues working. :slight_smile:

Yeah, like I said, it’s more of a band-aid than a surgery. You’re going to want to figure out if it’s an issue of your exporter/importer, or if it’s an issue with your actual model itself. Note that when you are editing a model in a 3D modeling program, vertex meshes are actually an object that stores mesh data inside of it. When you enter edit mode, it activates the mesh data. The mesh data’s invididual centers are a local transformation of the object’s point of origin, and as such, are zeroed in the context of the object itself. Meaning, you need to enter edit mode, and select the vertices of the model, and move them half of their height down on the z-axis (translated to Y by unity), and then exit object mode. This will fix the problem once and for all.

Well there was no model to import or export. The room was created in unity out of four cube objects. As I stated above I did this so that I could take advantage of using four cube colliders for each part of the room instead of modeling the whole room in another program,importing it, then using a mesh collider for the room as a whole.

TerXIII,

Thank you for this solution. No matter what I tried objects were importing with the axis in the corners instead of the centre where I’d set it. Your solution works well.