- Home /
Simulating 2D planetary gravity and trajectpry using Unity
I'm making a game that has planets rotating around a sun.
The player fires objects, spheres, etc from these planets that are influenced by the surrounding planets. My question is if there is a way/tutorial to predict the trajectory that these objects would take using line renderer, etc.
Something like this.
http://www.kongregate.com/games/meisvlk/learning-gravity-2
Also if anyone can point to some good tutorials for implementing a planet + sun system in unity that would be great.
I don't know if there are any tutorials, it should not be too hard in 2D. You may try the following;
create shapes for the sun and other planets. Assign a size to each of them.
at the start of scene, you would store them in a list, their positions and gravitational effect (caused by size), in a Vector3 for example.
when you shoot, bullets for example, it would be effected by this gravitation on every update. Simply you would measure distance of your bullet from a planet, then the force would be (baseForce * sizeOfPlanet) / $$anonymous$$athf.Pow(distance,2).
you would create a loop, and the above would be applied by each planet.
I hope this would help.
Sounds like this: http://en.wikipedia.org/wiki/Three-body_problem#n-body_problem
Your answer
Follow this Question
Related Questions
How to predict orbit based on time? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Advanced Orbit Camera Around Target 1 Answer
Itween for curved orbital movement? 1 Answer
Simple Planet orbit 3 Answers