3D : Why does gravity affect my horizontal speed when running ?

Hi there,

I am building a character controller using only the Physics system (moving around using rb.AddForce).
Using some basic math I figured that to reach a given speed I could use this formula to determine the force to apply :
F = massVdrag / (1-drag*Time.FixedDeltaTime)

Calculated from :
V = V*(1-dragdt)
V = V+acceleration
dt
a = F/mass

This works perfectly if I unable the gravity in the settings or straight up apply a force to counteract gravity. But with gravity on and while running on a flat surface, a pure horizontal movement, I don’t get the full speed. Why is gravity affecting my horizontal speed ?

Also if I increase the drag up to 99 I almost get my target speed but with a drap of 100 I can’t move at all anymore. Is it hard coded somewhere that 100 is a drag threshold to stop movement ?

My code for those interested :

            Vector2 inputMoveVector = playerControls.Input.Move.ReadValue<Vector2>();

            impulse = transform.forward * inputMoveVector.y
                     + transform.right * inputMoveVector.x;
            impulse = impulse.normalized;

            impulse *= rb.mass * runSpeed*rb.drag;
            impulse /= (1 - rb.drag*Time.fixedDeltaTime);

            rb.AddForce(impulse, ForceMode.Force);

You should check if any friction is applied. This would be enforced by gravity, as it would generate more collisions with the ground. Check the Physic materials on your colliders of both ground and the moving Rigidbody.

That was it, I didn’t know there was a default friction applied even with no physics material.
Thank you very much sir !