Search Unity

Consistent speed formula for 3D rigidbody using AddForce

Discussion in 'Physics' started by Afropenguinn, Jun 22, 2017.

  1. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    Perhaps it's by chance, or perhaps it's intended, but I managed to get my Rigidbody2D moving at a consistent speed while still using AddForce for acceleration:

    Code (CSharp):
    1. body.AddForce(virtualStick.normalized * speed * body.drag * body.mass);
    virtualStick is the direction the body is moving in.

    The result is that, no matter the linear drag or mass of the Rigidbody2D, it will accelerate until it hits 'speed' and that is where its motion will cap out. When I tried a similar formula with a 3D rigidbody, it didn't result in that consistent speed. Well, I should say that its top speed is consistent, just not what the 'speed' variable is set to. To clarify, neither of these bodies were using gravity. Could anyone explain what else needs to be accounted for in a 3D version of this formula?