Hi
I need help mam as the object rotates round the axis of the black cube. Because now object rotating own axis not black cube, as in image number 2.
I want rotate object around black cube, as in umage number 3ā¦ Can someone help me?
Thanks for reply
You could parent the rectangle to the square and then rotate the square or use transform.RotateAround.
So can someone give me example how to use transform.RotateAround? because alway my result is, object rotating own axis
The first parameter in RotateAround()
is the point (in world coordinates) it should pivot around - have you tried setting that to the position of the object you want to rotate around?
Expanding upon what @larku said with examples:
transform.RotateAround(Vector3.up); // Rotate object around the Y axis
transform.RotateAround(Vector3.right); // Rotate object around the X axis
transform.RotateAround(Vector3.forward); // Rotate object around the Z axis[code]
transform.RotateAround
ās signature is:
public void RotateAround([Vector3 ](http://docs.unity3d.com/ScriptReference/Vector3.html)point, [Vector3 ](http://docs.unity3d.com/ScriptReference/Vector3.html)axis, float angle);
Hence the axis must be the second parameter.
As such Iām pretty sure those examples should be more like:
transform.RotateAround(targetPivotPoint, Vector3.up, angle); // Rotate object around the Y axis
transform.RotateAround(targetPivotPoint, Vector3.right, angle); // Rotate object around the X axis
transform.RotateAround(targetPivotPoint, Vector3.forward, angle); // Rotate object around the Z axis
Thank you all for answers, but error was in code, the position of objX was determined by other code, so I did not notice of objX could not move around the axis black cube. Now its work how writed larku, but now still rotating around axis black cube. How to now do to objX turned around only when he turned black cube. I want to just copy the rotation black cube on axis x. Exactly the same way if it were a child of black cube but it is not