# Controlling a thrustered 2D space ship with angular rotation and max speed

In my game I have a computer controlled ship that is accelerated by a thruster: with a constant force and in the direction of the ship's current orientation/rotation angle.

Thrusting My ship has a maximum speed limit (velocity) and a maximum thrust power that can be applied each time to the velocity until maximum speed has been reached.

Rotating Given a "desired target" (click the screen on my demo), it determines the required angle and rotates by a constant angular force until it reaches the desired value.

Finding the angle and rotating is done. The problem is that the only way I know how to keep a speed limit is by limiting the ship's velocity vector before it is summed to the ship's location, but this way the ship is always thrusting (like in the video) only the effect is caped:

Thrusting only when required In a better approach, I only thrust if the ship orientation angle is aligned with the target angle.

While this is visually more effective, thrusting is still done at max power and still relies in limiting the velocity when the ship is thrusting.

What I need (and I can't do) I need to calculate the force that the thruster should apply to the ship's velocity to change the direction while keeping the overall speed not beyond the limit so I can get rid of limiting the ship's velocity.

Reading this thread I understand (I think) that I need to apply to the velocity only the component of the force that will affect the ship velocity angle and not its length. And I can determine this checking if the direction of the impulse (thrusting force) is orthogonal to the current direction of the ship's velocity and applying the relevant component of that force (x or y).

I did many attemps and all failed. So I came here with hope to find someone who is more familiarized with this or at least that can explain how to apply @dannuic reply to my code.

This is my code on github, just clone and if in Linux run ./simpleServer (may require chmod u+x).

Thank you very much!

Vec3 force = factor * (desired_velocity - current_velocity)