Constant velocity -> weird physics interaction


I am writing a subway surfer’s like game which uses a character with constant movement.
I also want to have instant left/right movement (aka. no force).

I am doing both with this snippet:

Vector3 vel = this.rigidbody.velocity;
float hAxis = CustomInput.GetHorizontalAxis();
vel.z = _currentFowardVelocity; // 8.0f
vel.x = hAxis * _currentHorzintalVelocity; // max 8.0f
this.rigidbody.velocity = vel;
// gravity
this.rigidbody.AddForce(25f * Vector3.down);

I set the Rigidbody Collision Detection to “Continuous” to
deal with the increased gravity.

But I still get issues with my rigidbody entering other fixed
objects and being stuck in them:
rigidbody inside static mesh

The rigidbody is a capsule collider and it’s stuck in a fixed
box collider in the picture abvoe. The physics material (dynamic|static) friction and
bounciness is set to 0.


  1. Is setting the constant velocity responsible for this behaviour?

  2. How do I fix this?

Note that I can avoid this issue by enlarging the capsule collider, but
then it doesn’t feel right since it’s way bigger than the board which it
should represent.


As per the Unity Documentation for Rigidbody.velocity it clearly states that:

In most cases you should not modify
the velocity directly, as this can
result in unrealistic behaviour. Don’t
set the velocity of an object every
physics step, this will lead to
unrealistic physics simulation.

For the solution rather than setting velocity you can use Rigidbody.MovePosition to move your rigidbody.