3D Rigidbody Character Dash with rb.MovePosition glitches through walls on steep angles

Hi o/

For a current project a friend of mine and try are trying to make a small low-poly-style game and our main character is supposed to be able to dash.
I was trying to use MovePosition on our Rigidbody instead of AddForce or modyfing Velocity because I tried all 3 and MovePosition looks the most dash-like. With the others the character seems rather floaty…
And as long as the terrain is not too steep it works like a charm, but whenever the character is trying to dash against a steeper Terrainpolygon like 45°ish or more he just glitches through the wall :frowning:

Does anybody know how to preven that?

Greetings Ken

MovePosition will forcefully move the body to the new position. At the same time the Physics engine will be trying to enforce the collisions. As both you and the physics engine are giving contradictory commands (“move” and “react to collisions”) then the results will be highly unreliable. Most times your motion commands will override the reactions to collisions.

The correct way of moving a rigidbody and reacting to collisions at the same time is using Rigidbody.AddForce. For example, if you want to impose a velocity you can apply a delta-velocity from the actual velocity:

rigidbody.AddForce (expectedVelocity - rigidbody.velocity, ForceMode.VelocityChange);

The above imposes a velocity (expectedVelocity) but allows the physics engine to react to collisions properly. For example, the rigidbody will stop against a blocking wall even if the AddForce command keeps trying to impose the velocity.