Hello everyone, I’m a 28 year old game developer, I’m pretty bad at math and geometry, it took over a week for me to work on it, I don’t know much about quaternions, I’m not such a bad developer, but I couldn’t do such a simple thing. I just need to hold an object at a certain angle in the orbit of another object, just like Transform.RotateAround which doesn’t rotate on its own but fixed at the specified angle.
Or it could be something like, a pseudocode that returns CubeB when CubeA rotated like in the gif below. (Unfortunately, in the project I am working on, I do not have a chance to make the orbiting object a child of the central object.)
I was able to use Transform.RotateAround this way using Quaternion.FromToRotation(for keeping the difference constant), but I have to write all this as a common static method and it gets over-parameterized like “Rotate in this axis, direction of rotation is that direction. etc.”…
Everything I can find on the internet works to automatically rotate the object around another object.
Why not make another empty GameObject the child of the central rotating one, then make the one that are not able to make into a child simply take its position each frame (such as in LateUpdate() ) and move to that position?
Otherwise perhaps make blank GameObject at the center and cause it to always mimic the real central core’s rotation, and child your position to that?
Then let me pry your brain open and fix that!
The math to compute a rotated position is simple enough:
// given this:
Quaternion rotation = ... however you set this
Vector3 center = ... however you set this
float distanceUp = ... however you set this
// then the rotated position is:
Vector3 orbitingPosition = center + rotation * Vector3.up * distanceUp;
That assumes you’re spinning around the Z axis, and that up is the identity rotation.
my goal is to make a static method as I mentioned. In the math you mentioned, we have to choose the distance of the object ourselves and if we write the difference of the object from the center where the distance should be, the object will rotate itself again. Maybe there will be more than one of objects and dealing with each of them is laborious. when we drag the object in the editor and choose its center, the distance should be that. for instance, this is how it is in Transform.RotateAround method.
If we are going to make a static method, it would still not be appropriate to store the difference of the object from the center at the start of the game or the beginning of a coroutine.
Ok, thanks, I’ve been struggling since yesterday, actually the problem is solved but I couldn’t add offset
By the way, When you said open my brain and fix that, I thought you meant my brain was like broken,(funny thing is I have OCD) I may have a little bit overreacted, excuse me for that…