- Home /
The question is answered, right answer was accepted
How to lock an objects orbiting focal point.
I am helping a friend to develop a small mobile app that can simulate very basic orbiting scenarios with different sized objects. Everything works perfectly except that I would like to somehow lock the 1-2 "planets" in the game world so that their combined center of mass Vector3 is always the center of the screen (or Vector3.zero). How hard would it be to make this work?
I currently have 2 objects that orbit around their common center of mass but their individual masses can be altered which shifts the center of mass.
You can also apply a force to one of the objects which will alter the objects orbit and depending on its mass, will indirectly affect the orbit of the other object.
I suggest actually using the gravitational bodies equations and seeing what your simulation runs like. Otherwise rotating things around 0 is pretty much what you've got.
Answer by Nomadx · Feb 27, 2015 at 03:39 PM
I actually figured it out on my way to work this morning. What I did initially was have both objects apply a force towards the other, based on the others mass. What I did to get it to do what I wanted was have an empty game object in the center of the world called "Center of Mass" and made the object I can manipulate orbit that object, the other object then orbits directly opposite except that it is either closer or further from the Center of Mass depending on the ratio between its mass and the mass of both objects.