- Home /
Rotate Object from Other Local Object
is there a way to rotate an object, on the current local axis of an other object?
something (this is not right) like this: transform.Rotate(-5,0,0,Space.GameObject.Find("OtherObject"));
Answer by aldonaletto · Jul 11, 2011 at 01:47 PM
Rotations are always tricky. If both objects have the same rotation at Start and have no parents, you can copy
transform.rotation from one object to the other - the second object will follow any rotation applied to the first one. If they are childed to other objects, however, you may have lots of weird effects.
EDITED: There is a function to rotate an object around any arbitrary axis, RotateAround. You can set this axis to some local vector of another object: use .up vector for Y, .right for X or .forward for Z.
It's not possible to rotate around more than one axis in a single RotateAround.
The example below rotate around the Y axis of the object defined in master:
var master: Transform; // reference object
function Update(){
var ang = Input.GetAxis("Horizontal") * 30 * Time.deltaTime;
transform.RotateAround(transform.position, master.up, ang);
}
Answer by Yanger_xy · Jul 11, 2011 at 09:52 AM
Do you mean Transform.localRotation ? The rotation of the transform relative to the parent transform's rotation. If so ,just change its value.
I mean that you can rotate an object like on the X axis en when you turn an other object, that it will twist object 1 on the local X as of object 2
Your answer
Follow this Question
Related Questions
pretty weird issue with rotating a sphere 2 Answers
Rotation script 2 Answers
A node in a childnode? 1 Answer
Disabling the Z axis? 1 Answer