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

2 Answers 2


Adding forces to a rigidbody won't change its velocity until the phyiscs engine runs another update, which happens betweeen two calls to a FixedUpdate method in your own code.

But if you want to predict the velocity of a body after applying a force, you can do so using Newton's formula force = mass * acceleration, or acceleration = force / mass.

Vector3 newVelocity = body.velocity + (Force / body.mass) * Time.deltaTime;

But keep in mind that drag, other forces and collisions with other bodies might cause the velocity on the next frame to be different than you predicted.

  • \$\begingroup\$ if force / rigidbody.mass is equal to acceleration then why do we add that to the new velocity? Shouldn't we add a velocity, instead of acceleration? This piece of code is on FixedUpdate(): Vector2 vel = rb.velocity; Vector2 newVel = vel + (force / rb.mass); Debug.Log(vel.magnitude + " vs " + newVel.magnitude); rb.AddRelativeForce(force); And it prints this which is not the result wanted. What I want is to predict the next "vel" \$\endgroup\$ Commented Feb 3, 2020 at 18:52
  • 1
    \$\begingroup\$ The above would be accurate after 1 second (acceleration here being in m/s). If you're sampling at some other point in time, you need to scale the Force/Mass part to the appropriate deltaTime. \$\endgroup\$
    – Basic
    Commented Mar 29, 2023 at 0:45

Remmber: F=MA

When you add force you are modifying the acceleration, which will in turn change velocity as time progresses.

You have added and subtracted force in the same instant, without allowing time for the newly changed rate of acceleration to modify the velocity. Add some brief sleeps in your code and you will see the change in velocity.

  • \$\begingroup\$ The brief sleeps won't work because the prediction has to be instant \$\endgroup\$ Commented Feb 3, 2020 at 19:15
  • \$\begingroup\$ I think you are fundamentally misunderstanding the basis of real world physics which the game engine is attempting to simulate. Regardless of the magnitude of the change in force, there will be no change in velocity until there has been a change in time. \$\endgroup\$ Commented Feb 3, 2020 at 19:17
  • 2
    \$\begingroup\$ @PanagiotisIatrou I think this may be an X/Y problem. If you provide some more specifics about your situation and what you are trying to accomplish I think someone will be able to provide a more specific answer. It is hard to understand what exactly the inputs and outputs you are looking for are, and what your current implementation is. \$\endgroup\$ Commented Feb 3, 2020 at 19:22
  • \$\begingroup\$ I edited the question body \$\endgroup\$ Commented Feb 3, 2020 at 19:35

You must log in to answer this question.

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