Hi,
I am currently developing space "racing" game where the players will use local gravity fields (planets, stars, black holes) to slingshot their ships around.
I would like to draw predicted trajectory based on current position and velocity. So far I was able to implement this feature using scripts by managing the gravity by myself. The map is static and I can calculate the force pulling the player based on position.
My algorithm is:
- get current position and velocity
- calculate the gravity force for the position
- calculate velocity change and get new position
- repeat multiple times ([number of physics steps per second] * [prediciton length in seconds]), store points in array
- draw polyline
This system works great, but I would like to use Area2D (with point gravity and gravity falloff) to do this for me since I it is already implemented and potentially much faster than scripted solution. I will still run the prediction loop from script but I would like to get the gravity vector from physics server based on global_position.
Is there a function to get gravity vector based on the global_position from the physics server?
So far I was unable to locate the method where is the gravity force is actually calculated for area2D. Can someone point me to the right direction?
Thank you