- Home /
How to rotate around the parent in 2D?
I want to make a game object rotate around its moving parent in a 2D game, but all examples and questions I've found are related to 3D.
Do you know how to achieve this? Is there any method to rotate around a given pivot point or specific game object while this is moving?
I think of 2D as top-down or sidescrolling, and to me "rotating around" something implies depth so I'm having a hard time visualizing this.
Never worked in 2D. But i used a 2D view of a 3D world. So i would say use transform.RotateAround like u would in 3D, except it would work in 2D. If there is no sense of depth in ur game, then the object rotating will fall behind the parent. And it can rotate around along the XY plane and never change depth
Answer by ReverendDe4th · Jan 24, 2015 at 08:04 PM
The way I've accomplished this in either 2D or 3D is to create an empty game object at the location of the parent. Do not parent the empty game object with the parent. Create a simple script that positions the new game object at the origin of the parent. It would be something like so:
public transform Target;
void Update() {
gameObject.transform.position = Target.position;
}
After that, it should just be a matter of attaching your orbiting object to the empty game object you created. Now when you rotate your new game object, your orbiting object should rotate around the parent.