Keep gravity velocity the same all the time

I have 2D rigidbodies that fall to the ground, however they speed up while falling. Also, when they freeze in the air and then unfreeze, the velocity is set to 0 and they gradually start speeding up again. How can I keep the velocity constant at all times, until they hit the ground?

• Set velocity manually in update when you detect the object is falling Feb 21, 2016 at 21:33
• vVelocity = ceiling(clamp(vVelocity.length, 0, 1)) * vFallSpeed
– Jon
Feb 21, 2016 at 23:18
• What do you mean by freeze in air? Apr 23, 2016 at 13:12

Fixed by setting Linear Drag in RigidBody 2D at 1.1 (value depends on gravity, etc), which damped the fall speed and now the objects don't accelerate with time when falling.

Rotation can also be damped by setting Angular Drag to the appropriate value.

Disable gravity for the object as you'll no longer be wanting it to interfere. Have some reference to the object's Rigidbody, as well as some way to determine whether the object/character is jumping - in which case you will probably apply some upward velocity for a short time. If it's not jumping, you can manually set the velocity of the body, applying the constant downward factor you're looking for.

void FixedUpdate()
{
if(!jumping)
{
Vector2 currentVelocity = rigidbody.velocity;
rigidbody.velocity = new Vector2(currentVelocity.x, -9.81f);
}
}


Make a script that will check for the magnitude of the rigidbodies like so:

if(GetComponent<RigidBody>().velocity.magnitude > MAX_SPEED){ GetComponent<RigidBody>().useGravity = false; }

This will make sure that your rigidbodies can't have a speed higher than your preset value.