character_controller_up_vector
The up vector instructs the character controller of what direction should be considered vertical. The horizontal plane is the plane orthogonal to this up vector. There are two equivalent ways to evaluate the slope of the floor: by taking the angle between the floor and the horizontal plane (in 2D), or by taking the angle between the up-vector and the normal of the floor (in 2D and 3D). By default, the up vector is the positive y axis, but it can be modified to be any (unit) vector that suits the application.
- Example 2D
- Example 3D
/* Character controller with the positive X axis as the up vector. */
commands
.spawn(Collider::ball(0.5))
.insert(KinematicCharacterController {
up: Vec2::X,
..default()
});
/* Modify the character controller’s up vector inside of a system. */
fn modify_character_controller_up(
mut character_controllers: Query<&mut KinematicCharacterController>,
) {
for mut character_controller in character_controllers.iter_mut() {
character_controller.up = Vec2::X;
}
}
/* Character controller with the positive X axis as the up vector. */
commands
.spawn(RigidBody::KinematicPositionBased)
.insert(Collider::ball(0.5))
.insert(SpatialBundle::from_transform(
Transform::default().with_translation(Vec3::Z * -10f32),
))
.insert(KinematicCharacterController {
up: Vec3::X,
..default()
});
/* Modify the character controller’s up vector inside of a system. */
fn modify_character_controller_up(
mut character_controllers: Query<&mut KinematicCharacterController>,
) {
for mut character_controller in character_controllers.iter_mut() {
character_controller.up = Vec3::Y;
}
}