So, when your velocity and acceleration are perpendicular to each other, you will “orbit”.
And if they arent exactly pointing in the same direction, there will be a portion that is perpendicular, giving an orbit like effect of varying degree.
Tldr: in the end, you just need to add a perpendicular acceleration to the current acceleration (opposing the orbit) to cancel it.
Also, I am sure there is an easier way than outlined below. But it was just my thinking off the top of my head. I can revisit this later when I have time to streamline it some.
Assuming the total thrust is limited, this is what I would do:
(Edited)
- find unit vector pointing to target
- just divide any vector pointing to target by its magnitude (length)
- find paralell and perpindicular components of current velocity with respect to that vector
- more than one way to do this
- take dot product to get paralell portion
- subtract that portion from original to get perpendicular
- Use that result to determine how much acceleration should be used to accelerate toward target vs how much to break orbit
- personally I would multiply the perpindicular portion by a variable to adjust how much breaking the orbit is prioritized.
- add perpendicular and parallel portions together, normalize, and multiply by total desired thrust (max acceleration?).