- Home /
Rotate an object such that it is theta degrees relative to another object
I have two cubes where one is static and another moves freely.
The point of the program is to move a cube by a random increment (for the X and Z coordinates) till they reach the ideal distance and ideal angle (10 units and 45 degrees) and they're supposed to move and rotate only along the XZ Axis (The camera is orthographic pointing downwards along the Y axis).
Right now I have the moving part of it figured out and working perfectly.
The only thing I have a problem with is the rotating part.
I tried moving the cube relatively to the static cube but when I do that, the moving cube pivots around the static cube instead of rotating in its place to an angle such that it makes a 45 degree angle with the static cube. I did the above using: transform.RotateAround(staticCube.transform.position, Vector3.up, 45);
and it does not work.
Any ideas on how I can do this?
Is there any chance you can post a picture or video of what you're trying to achieve? It's kind of hard to understand what you're explaining without a visual image.
hello, you want the object to rotate arround the object or to rotate in place?
@xxmariofer It has to rotate in place such that the angle between the two cubes is 45 degrees
you mean something like the object rotationof object a is (0,0,0) and object be (0,45,0)?
Answer by Captain_Pineapple · Feb 07, 2019 at 12:10 PM
Hey there,
just a wild guess but this should solve your issue:
transform.RotateAround(transform.position, Vector3.up, 45);
RotateArounds first argument is the position that you will use as pivot. So easier would probably be to use transform.Rotate()
here since it defaults to transform.position
as pivot point. (Not tested but i think it's this way. Let me know if that was wrong :))
That's what I am doing now and it doesn't seem to work the way I need it to.
But the code you provided is not the same as the one i posted in my answer. Did you test my solution?
Your answer
Follow this Question
Related Questions
Global movement 0 Answers
Camera Relative Movement 2 Answers
Setting z value of trans.pos relative to rotation 1 Answer
2d Movement Messes up when cube is rotatated 0 Answers
How do I check a rotation relative to another object's rotation? 1 Answer