First post. Be gentle.
- I have 2 RigidBodies (Star is Static and Planet is Character)
- Both bodies have Area2D with Combined Gravity points.
- Global gravity is disabled.
- More planets could be added and the idea is for each to Combine their gravity with the Star to give a n-body-like effect.
But for now I have 1 Planet to orbit around the Star.
During startup I want to set each Planet's velocity so that it is in a perfect orbit around the sun (ignoring for now the fact that each planet will interfere during n-body calcs).
However when I attempt to calculate the velocity required for circle orbit I find that the velocity is waaay to low to keep the planet moving in circle. This results in the planet plunging into the star.
I think I'm missing something obvious - here is current code in my ready function:
` func _ready():
# set initial estimated veloc for each planet based on distance to star
for member in get_tree().get_nodes_in_group("planet"):
var direction = member.position.direction_to($Star.position)
var distance = member.position.distance_to($Star.position)
var bigG = 6.6743 * pow(10, -11) # does this need tweaked?
print("G ", bigG)
var mag= sqrt((bigG*($Star.mass+member.mass))/distance) # m/s
print("mag ", mag)
var accf=(bigG*($Star.mass+member.mass))/(distance*distance) # not used currently
print("acc ", accf)
var velo=dir_tangent * mag # * 4000000 # seems that multiplying by about 4mil gives me almost a circle orbit
print("velo ", velo)
Fumbling with this for a few hours I noticed that if I multiply the MAG by about 4,000,000 then I get the (almost) circular orbit... something tells me that isn't the right way to handle it and that probably won't work for just any distance.
Please let me know if I can add more details.
- What am I missing?
- Am I misunderstanding unit conversions (pixels to meter?)
- Is the gravity Acceleration Force even needed in this calculation?
- What role does the Gravitational constant play here and if that needs tweaked how would I do that so that it works for planets at varying distances?
Godot version v3.3.3.stable.official [b973f997f]