I'm making a top-down 2D space ship game in which you rotate and thrust. I'd like to impose a maximum velocity for different engine types, meaning that a certain engine can only get you going up to a certain speed.
But I'd also like the ship to be able to travel faster than that maximum velocity, say if it were sent flying by a collision with a fast-moving asteroid.
I can't naively have the engines only apply impulse if the ship is moving at less than its maximum speed -- otherwise if an asteroid sent you flying to the right, you couldn't deliberately slow down because that would involve applying an impulse to the left.
But I'm not restricted to cardinal directions. If the ship is moving too fast to the right, I don't want it to accelerate to the right, but I would like it to be able to curve upward, which might involve applying some kind of impulse at say a 15 degree angle.
My other thought was to cap the maximum velocity of the ship at the maximum velocity of the engine, but then an asteroid collision could send you flying no faster than you engine's maximum speed, and that's undesirable as well.
How might I go about designing a system that allows one to reach velocities no higher than a set maximum from their own impulse, but still be able to steer their ship at higher velocities and still actually attain those higher velocities from external means?
Edit
Let's say my maximum velocity is 50 m/s. I'm traveling at 50 m/s at a 15 degree angle, which means my x velocity is 48.3 and my y velocity is 12.9. The ship is facing at a 30 degree angle (even though it's traveling along a 15 degree vector).
When I press the thrust button, I want the ship to trend toward that 30 degree angle of travel. Which means that its current angle of travel must be altered in some fashion. Right now I do so by applying impulses. But if I apply an impulse at a 30 degree angle, the ship's velocity will exceed is maximum (a good portion of that impulse is in the same direction as we're already going).
If I don't allow that impulse to be applied, the player can't adjust their course at all while they're moving too fast. And I'm not sure how to determine which components of an impulse would change a ship's velocity's angle without increasing its length.
speed_going_right
is absolutely less than the maximum. In fact, it's negative! \$\endgroup\$if speed > maximum speed = speed - whatever number that fits your needs
also, if the speed is higher than the maximum speed don't increase the speed by the acceleration amount \$\endgroup\$(-3,2) + (0.5,0.5)
has a different magnitude than(3,2) + (0.5,0.5)
. The first is 3.53 the other is ~4.30, if your maximum speed is 4, then the former is allowable and the latter is not. \$\endgroup\$