I’ve created a game where the player fires a projectile between planets trying to hit a target. The planets then apply their gravitational forces to the projectile. All of this is working correctly. What I now want is to use a LineRenderer to give a prediction of where the projectile will fly. This is where my math skills fail me.
All projectiles originate from one location and always at the same initial speed. The only variable that changes is the direction.
When a projectile is fired I apply a force to the rigidbody
rb.AddForce(origin.up * VELOCITY)
As soon as the projectile is spawned all gravitational entities in the scene starts pulling on it.
float forceMagnitude = (projectileMass * planetGravity) / Mathf.Pow(distance, 2); Vector2 force = direction.normalized * forceMagnitude; rb.AddForce(force);
I’ve experimented somewhat trying to solve this and have managed to get a line which loops around the planets. However it doesn’t match the path the projectile flies. So something is off. I think my calculation around applying gravity and how to simulate the initial velocity.
My goal is to have something similar to the game Orbit (Steam)
Do you guys have any insight in how I can tackle this? I think I just need a nudge in the right direction.