When I rotate an object using the rotation icon in the editor it rotates around itself, but when I try to do it with a script it appears to be rotating around a different axis (not necessarily around itself)… How can I fix it?
using UnityEngine;
using System.Collections;
public class SimpleRotate : MonoBehaviour {
void Update () {
transform.Rotate (Vector3.right * 50 * Time.deltaTime, Space.World);
}
}
public void Rotate(float xAngle, float yAngle, float zAngle, Space relativeTo = Space.Self); Description
Applies a rotation of zAngle degrees around the z axis, xAngle degrees around the x axis, and yAngle degrees around the y axis (in that order).
Guys, I think you all misunderstood me, and I finally understood the core of my problem. Since my objects’ points of rotation are not in the middle, unless I do a funny workaround it’s best just to re-export it in a 3D modeling program with the axis in the middle. That ought to solve my problem.
TLDR: If you have a 3d model on a parent empty game object, make sure the child’s position is 0, 0, 0.
After having this same problem, I figured it out.
My original “player” game object, consisting of a 3d model childed to an empty game object and with similar code to the above, was rotating around a random point for no particular reason
I deleted and rebuilt my player game object with an empty and a simple cube shape. I have the setting to place objects at the world origin when I create them in the hierarchy, so both the empty and 3d object’s positions were the same.
When I reimported my player graphic and parented it to the empty, I noticed it (the child’s) position was not Zero’d, however that was not obvious when just clicking the empty parent game object and viewing it in the inspector.
Thus, make sure the child game object’s position is 0, 0, 0.
This is exactly what I came to figure out. Once I zero’d all the children’s position coordinates, placed the parent object, moved the children in relation to the parent, then it spun around a center anchor point. Thank you so much!
If you add a BoxCollider to the empty object it would tell you exactly where is its pivot, this really helped me to visualize where to put the children objects in relation to their parent.
That’s bad idea considering that’s an active component that has behaviour and is part of a build i.e. a hammer to scratch and itch.
Just use the built-in custom icons in the Inspector window (See: “Assign custom icons to GameObjects, scripts, and Prefabs”). Adding in a small circular coloured dot should suffice?
Note: Please bear in mind that this thread is very, very old so please try to avoid necroing posts.