I am trying to implement a space rocket in 2D. Whenever the player presses a button, a constant force (Both vertical and horizontal) is being added to that rocket. What I want to add is a maximum speed, the rocket cant exceed as the rocket will continue accelerating to infinity. The player can also choose not to accelerate, which can lead to the rocket starting to fall down due to gravity. Thus, I cant just Clamp the rigidbody.velocity of the rocket whenever the magnitude of it exceeds max speed as it will also limit the fall velocity which is not as limited. Thus, I am trying to predict whether the player will exceed the maximum velocity when trying to accelerate, in order not to add the force.
So far, I have tried doing this but the velocity vector does not seem to change immediately, so vel is equal to postVel:
Vector2 vel = rigidbody.velocity;
rigidbody.AddRelativeForce(Force); // Add force
Vector2 postVel = rigidbody.velocity;
rigidbody.AddRelativeForce(-Force); // Undo force