How do I calculate path to intercept a moving object?

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

I am trying to understand a simple concept to decide if a given project is viable or not, and I’ve hit a situation in which my math - non existent - abilities are giving me a big problem.

Here is a image of the problem:
The image depicts three objects, object A, a spaceship in the middle left of the image, object B a planet and object C a star in the middle of the image. A red line is drawn around object C to serve as path to object B.

  • objA’s objective is to intercept objB in it’s orbit around objC using constant speed.
  • objB follows an orbital path in constant speed and maintaining the same distance to objC.
  • objC is stationary and serves only as to point the center of objB’s rotation.

How do I calculate the path in which objA has to travel in order for it to intercept objB in it’s orbit without changing its speed nor direction midflight?

:bust_in_silhouette: Reply From: Ertain

Have you tried about using a Kinematicbody2D node and the test_move() function?

I’ve read the test_move() function. As I understood it, it checks if there’s going to be a collision in a given location. The problem with this approach is that it would always return false, because the objcB is constantly moving.

As I see it, calculating the correct location in the future where objcB will be located and when objA will be able to meet it.

Somar | 2021-03-15 01:49

:bust_in_silhouette: Reply From: exuin

I will attempt to make one of the solutions in Godot and comment if it works out

:bust_in_silhouette: Reply From: exuin

I used a binary search to calculate the trajectory of the ship. Here is the GitHub repo link.

Interesting. I’ll do some research on binary search. There seems to be a bug on the demo though, the ship always misses the planet on the upper right side of the screen.

enter image description here

Somar | 2021-03-16 19:03

Yeah, I guess the search is not accurate enough. I will see if I can improve it.

exuin | 2021-03-16 19:04