2
\$\begingroup\$

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?

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

3 Answers 3

1
\$\begingroup\$

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.

\$\endgroup\$
0
0
\$\begingroup\$

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);
    }
}
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

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