character_controller_stairs
If enabled, the autostep setting allows the character to climb stairs automatically and walk over small obstacles. Autostepping requires the following parameters:
- The maximum height the character can step over. If the vertical movement needed to step over this obstacle is larger than this value, then the character will be stopped by the obstacle.
- The minimum (horizontal) width available on top of the obstacle. If, after the character is teleported on top of the obstacle, it cannot move forward by a distance larger than this minimum width, then the character will just be stopped by the obstacle (without being moved to the top of the obstacle).
- Whether or not autostepping is enabled for dynamic bodies. If it is not enabled for dynamic bodies, the character won’t attempt to automatically step over small dynamic bodies. Disabling this can be useful if we want the character to push these small objects (see collisions) instead of just stepping over them.
The following depicts (top) one configuration where all the autostepping conditions are satisfied, and, (bottom) two configurations where these conditions are not all satisfied (left: because the width of the step is too small, right: because the height of the step is too large):
Autostepping will only activate if the character is touching the floor right before the obstacle. This prevents the player from being teleported on to of a platform while it is in the air.
Autostepping is configured with r3KinematicCharacterController_SetAutostep, which takes whether it is enabled, the
maximum height and minimum width (both as R3CharacterLength, see the
character offset), and whether it is enabled for dynamic bodies. The
current settings are given by r3KinematicCharacterController_Autostep as an R3CharacterAutostep structure:
// Set `enabled` (the second argument) to 0 to disable autostep (the other arguments are then ignored).
r2KinematicCharacterController_SetAutostep(character_controller, 0, (R2CharacterLength){0},
(R2CharacterLength){0}, 0);
// Autostep if the step height is smaller than 0.5, and its width larger than 0.2.
r2KinematicCharacterController_SetAutostep(
character_controller, 1,
(R2CharacterLength){.value = 0.5, .relative = 0}, // The maximum height.
(R2CharacterLength){.value = 0.2, .relative = 0}, // The minimum width.
1); // Include dynamic bodies.
// Autostep if the step height is smaller than 0.3 multiplied by the character's height,
// and its width larger than 0.5 multiplied by the character's width (i.e. half the character's
// width).
r2KinematicCharacterController_SetAutostep(
character_controller, 1,
(R2CharacterLength){.value = 0.3, .relative = 1}, // The maximum height.
(R2CharacterLength){.value = 0.5, .relative = 1}, // The minimum width.
1); // Include dynamic bodies.