|
I want to rotate an object around its center point. I've tried To give some more detail my object is an empty gameObject containing several children, I'm translating my parent object to a specific position and doing two rotations, one My original code was this:
(comments are locked)
|
|
When you modify the rotation of a Transform, the rotation happens around the local origin - that is, the center of the local coordinate system for the object. The actual middle of the object may not be placed at the origin - that depends on how it was modeled. To make the rotation around the actual middle, there are a few things you could do.
There is at least 1 case ( http://answers.unity3d.com/questions/137688/pretty-weird-issue-with-rotating-a-sphere.html ) in which neither of these work (when importing a messed up mesh with pivot not in center), and they both look messy. Is there any "cleaner" solution nowadays? (years after this answer)
Jun 04 '12 at 07:45 PM
Cawas
Still keeping an interest in the question above (is there a more pleasant solution), I need to fix my mistake: using
Jun 04 '12 at 10:00 PM
Cawas
Here's the answer to my questions: use a new parent
Jun 11 '12 at 08:01 PM
Cawas
(comments are locked)
|
|
Rotating objects in the Unity3d Engine is extremely easy. For instance, I use the following code to rotate an object in the scene 360 degrees: function Update () { } Just create a new JavaScript, and paste this inside the script! @Pixelblock Games - I usually like to read the entire thread before posting an 'answer'. In doing so, it helped me see that torg is presenting a considerably more-complex issue, which your answer does not help with at all.
Mar 23 at 04:09 PM
grojguy
(comments are locked)
|
|
Like Ducky stated, we would need to see your code. I am wondering where you are updating the rotation and how. Its one thing to call transform.Rotate but where are you doing this and how often? For instance this works for me:
(comments are locked)
|
|
This has been a struggle for me as well. The only way I've been able to do this without creating any empty parents, clutter, etc is using an armature in Blender (assuming you're also using Blender :) I'm using it for a model that doesn't require a deform, meaning that each bone is assigned to a separate object. Also ensure that the bones have proper parenting hierarchy.
This will rotate the bone and the attached object 45 degrees around the X-Axis using its own pivot point instead of the pivot point of the entire game object. I'm pretty new to Unity so this may not be the most effective way, but I wasn't able to find much info on how to do this.
(comments are locked)
|
|
It sounds like you might need to give some thought to the way you compose consecutive rotations. By default, the Transform.Rotate method always rotates using the object's local coordinate system. This system does not change when you move or rotate the object. So if you rotate the object 90 degrees around Vector3.right, then what you might think of as the Y-axis in the scene/editor is the local Z-axis. (Note: in recent versions of the Unity editor you can choose whether the tool handles are displayed using local coords or not. Select your object, and click on the button marked "Global" or "Local" above the Scene View to switch from one to the other.) If you want to rotate around the world's "up" direction, regardless of the object's local coordinate system, you can try adding Space.World as the last argument to Rotate. Alternatively you can use only local coordinates for your work. You will need to rotate around the local axis that represents Up from the object's point of view, regardless of how its current orientation in the world. (Again, you can tell the Scene editor to display the rotation/translation tool handles in the local coordinate system to help keep this straight.) One additional comment: if the first 90 degree rotation is being done to correct an orientation problem with the model, you might consider doing that in the modeller instead. By defining the correct "up" and object center in the modeller, you make working with it in Unity a bit more intuitive. (I suppose another way around this might be to rotate the object 90 degrees, then parent it to a new game object whose local coordinate system is more to your liking. This is not something I've tried though.)
(comments are locked)
|

could you include the code that you're trying? the basic "transform.Rotate()" function should rotate an object around its own centre point, so if you're calling this on the empty parent, the children should all get rotated around it.
It may also be worth checking the coordinates of the children in the Inspector window, as they will be relative to the parent (ie EmptyGameObject). The little trasform gizmo appears to be drawn in the approximate centre of the object and children collectively, not at the parent's origin as in other programs like 3D Max.
Is there anyway to set the actual pivot or center of the parent gameObject? Looking at it in the scene view, the pivot (or transform gizmo) is at the approximate center of the object, which I've made sure of by moving it along the x-axis to make up for the individual positions of the children. This is why I cant understand that the rotation does not respect this center point in the script, but clearly does when the rotation is performed in the editor.