Force circular orbits in Area2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Artemas

I want my spaceship to be forced into a circular orbit when it enters an Area2D with point gravity. I am new to Godot so I’m not quite sure what I’m doing, but I think ideally I would have signal “_on_Planet_area_entered(area)” inside the spaceship script that sets the orbit to be circular around that planet.

I have messed around with the point gravity in Area2D and it only seems to give me elliptical orbits. I was also thinking it may work to have a wave function set as the point gravity value in Area2D, but I could not figure out how to have a wave function as a value in an inspector field.

example of what I want in green vs what I’m getting with area2D, in red
https://imgur.com/a/WhAKIMf

I’m also new to Godot but I call tell you something. The red line is correct, your object is probably too fast to orbit the Area2. I have two ideas about that, and they aren’t direct solutions, so this is a comment. Learn physics (I’m physicist) and understand how speed and other parameters affect the orbit, then if your object has the correct speed to enter in a circular orbit, when you want, make a boost in the velocity via code to exit the orbit. The second option is to apply some maths and find a way to describe the trajectory you want with trigonometic functions to orbit and a right line to exit (physics is not always needed in videogames). That’s only my opinion, not trivial solution.

abelgutierrez99 | 2021-09-12 12:26