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:

Check: Thruster space ship in action (youtube)

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

Check: A better approach (youtube)

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!


1 Answer 1


The applied force should be proportional to the desired velocity, relative to the current velocity.

In that case, if the current velocity is zero, the force will be proportional to the desired velocity.

If the current velocity is the desired velocity, the force will be zero.

Vec3 force = factor * (desired_velocity - current_velocity)

The proportionality factor is something that will depend on the scale of your game.

  • \$\begingroup\$ Hi, thanks for your reply! I think I get what you mean. Let me try some sketches at home and if it works I'll mark your reply as best answer and share code for others. \$\endgroup\$ Feb 27, 2019 at 21:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .