Rotate Around Object, in Absolute Angles?

Basically, I want the exact functionality of Transform.RotateAround() (object A rotates around object B along specified axis by x degrees), except I want to specify the angle in absolute terms, not relative terms.

Presently, if you do something like transform.RotateAround(Vector3.zero, Vector3.up, 20), the object would rotate around the world position 0,0,0 along the Vector3.up axis by 20 degrees every time that the method is called. So if I ran the above code 5 times, object A’s final angle would be 100 degrees greater than its starting angle.

Instead, I want it to take the angle in absolute terms, so if I ran transform.RotateAroundAbsolute(Vector3.zero, Vector3.up, 20) five times, the angle of the rotated object would still be 20.

I haven’t been able to find a direct method that will do this, though I’m aware I can use Quaternion.LookAt() to do part of the required functionality: getting the rotated object A to always face the object B that it’s rotating around, but how do I actually make object A physically position itself around object B based on an inputted angle?

what you are looking for is eulerAngles.

Maybe that’s a solution as well, though I’m not sure what that would look like.

I ended up going with a suggestion I got from the chat:

transform.rotation = Quaternion.AngleAxis(angle, Vector3.back);
transform.position = objectB.transform.position + Quaternion.AngleAxis(angle - 90, Vector3.back) * new Vector3(distance, 0, 0);
1 Like

yeah, this is a possible solution.
Another solution would be: placing the object inside an empty object, shift its local position and then rotate the empty parent object.

@Cybearg : what is the 90 for?

If I recall, it was to make the angles relative to a clock-like rotation, with 0 degrees being at 12 o’clock, rather than the standard 0 degrees being 3 o’clock.