Skip to main content

character_controller_slopes

If sliding is enabled, the character can automatically climb slopes if they are not too steep, or slide down slopes if they are too steep. Sliding is configured by the following parameters:

  • The max slope climb angle: if the angle between the slope to climb and the horizontal floor is larger than this value, then the character won’t be able to slide up this slope.
  • The min slope slide angle: if the angle between the slope and the horizontal floor is smaller than this value, then the vertical component of the character’s movement won’t result in any sliding.
info

As always in Rapier, angles are specified in radians.

// Don’t allow climbing slopes larger than 45 degrees.
character_controller.max_slope_climb_angle = 45_f32.to_radians();
// Automatically slide down on slopes smaller than 30 degrees.
character_controller.min_slope_slide_angle = 30_f32.to_radians();
/* Configure the character controller when the collider is created. */
commands
.spawn(Collider::ball(0.5))
.insert(KinematicCharacterController {
// Don’t allow climbing slopes larger than 45 degrees.
max_slope_climb_angle: 45_f32.to_radians(),
// Automatically slide down on slopes smaller than 30 degrees.
min_slope_slide_angle: 30_f32.to_radians(),
..default()
});
/* Configure the slopes inside of a system. */
fn modify_character_controller_slopes(
mut character_controllers: Query<&mut KinematicCharacterController>,
) {
for mut character_controller in character_controllers.iter_mut() {
// Don’t allow climbing slopes larger than 45 degrees.
character_controller.max_slope_climb_angle = 45_f32.to_radians();
// Automatically slide down on slopes smaller than 30 degrees.
character_controller.min_slope_slide_angle = 30_f32.to_radians();
}
}
let characterController = world.createCharacterController(0.01);
// Don’t allow climbing slopes larger than 45 degrees.
characterController.setMaxSlopeClimbAngle(45 * Math.PI / 180);
// Automatically slide down on slopes smaller than 30 degrees.
characterController.setMinSlopeSlideAngle(30 * Math.PI / 180);

Both angles are set at once with r3KinematicCharacterController_SetSlopes. Sliding itself is enabled by default, and can be disabled with r3KinematicCharacterController_SetSlide. The current slope angles and sliding setting can be read with r3KinematicCharacterController_Settings.

r2KinematicCharacterController_SetSlopes(
character_controller,
// Don't allow climbing slopes larger than 45 degrees.
45.0 * R2_PI / 180.0,
// Automatically slide down on slopes smaller than 30 degrees.
30.0 * R2_PI / 180.0);

The angles are set with the max_slope_climb_angle and min_slope_slide_angle properties. Sliding itself is enabled by default, and can be disabled by setting the slide property to False.

# Don’t allow climbing slopes larger than 45 degrees.
character_controller.max_slope_climb_angle = math.radians(45.0)
# Automatically slide down on slopes smaller than 30 degrees.
character_controller.min_slope_slide_angle = math.radians(30.0)