When an object is controlled by a CharacterController, it is easy to make it climb ramps with a certain slope, or climb steps with a certain height.

When the object is controlled by a RigidBody instead, it can still climb ramps naturally - I just use AddForce and it walks on ramps just like on any other surface. I do not have to add any special logic for a ramp. However, it does not climb stairs. Is there a natural "physical" way to make the RigidBody climb stairs, without explicitly checking that there are stairs ahead?

  • 1
    \$\begingroup\$ What shape is your collider? Does it have a rounded edge that can lift it up and over the step, or a hard corner that will snag? \$\endgroup\$
    – DMGregory
    May 14 '20 at 11:46
  • \$\begingroup\$ @DMGregory It is a capsule. \$\endgroup\$ May 14 '20 at 13:21

In order to lift a capsule up the stair's riser, the normal force exerted by the stair corner against the rounded bottom must meet or exceed the force of gravity pulling it down.

Given a particular capsule radius \$r\$ and riser height \$h\$, both sitting on the same floor plane, the corner hits the capsule at a point relative to its center of curvature:

$$ \vec p_{contact} = \left( \sqrt{r^2 - h^2}, h - r\right)$$

Which means the normal force will act in the direction given by the unit normal:

$$\vec n = \frac {-1} r \left( \sqrt{r^2 - h^2}, h - r\right)$$

To lift off the ground, the vertical component of this force has to equal or exceed the force of gravity, given by an acceleration \$a_g < 0\$:

$$\begin{align} f \cdot \frac {h - r} r &= m \cdot a_g\\ f &=\frac { m \cdot a_g \cdot r} {h - r} \end{align}$$

This will then try to push your capsule backward away from the stair by the horizontal component of the force:

$$f_{horizontal} = \frac { m \cdot a_g} {h - r} \sqrt{r^2 - h^2}$$

So you'll need to drive your capsule into the stair with a force greater than or equal to this amount to achieve lifting. Plus some extra to overcome losses to friction.

  • \$\begingroup\$ Very interesting, thanks! So the reason that my capsule did not climb the stais was just that the force was too small. \$\endgroup\$ May 19 '20 at 8:01

You must log in to answer this question.

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