Search code examples
c#unity-game-enginephysics

Unity - How to draw the orbit trajectory


A few days ago I watched a video called "Coding Adventures: Solar System" which was made by Sebastian Lague. It inspired me to make my own simple simulation of the Solar System. Everything was fine until I needed to draw the orbit trajectory to set my Initial Velocity properly. I was searching and searching and didn't find anything. So here's my question. How can I draw an orbit trajectory in Unity?


Solution

  • The script he uses for the trajectory is in the Debug folder: https://github.com/SebLague/Solar-System/blob/Episode_01/Assets/Scripts/Debug/OrbitDebugDisplay.cs He basically create a new fake CelestialBody for each planet and calculate every position. He uses both DrawLine and LineRenderer.