- Home /
Rotate cube according to position of another object?
I have a level as shown below.
I want to press any arrow key and the blue cube will 'rotate' or move position to same position but on a different face of the white cube.
I want this to work so whatever arrow key you press it will move it to the same relative position but on a different face of the white cube. I can't figure out how to manage this any help is much appreciated.
Answer by pinkwerks · Jan 20 at 07:08 AM
You can parent an object to another object, and it will move along with it. So, when you press a key, set the blueCube to be a child of another transform of your choosing. Then perform the animation on the new-parent. If you keep world position when stetting the parent, the object will stay put, even though it "follows" a different object.
// ...pick a newParentTransform
blueCube.transform.SetParent(newParentTransform, worldPositionStays=true);
// ...play an animation that does the rotation
Another possible approach is to set the rotation directly with Transform.RotateAround
Your answer
Follow this Question
Related Questions
Rotate an object such that it is theta degrees relative to another object 1 Answer
simple 360 degree Cube-rotation around y axis 2 Answers
Calculate rotation angle for two side of cube ( like dice ) from Quaternion.identity 0 Answers
rotate object on transform.right 3 Answers
rotate an image by modifying Texture2D.GetPixels32() array 2 Answers