pub struct CharacterController {
pub position: Vec3Fix,
pub velocity: Vec3Fix,
pub grounded: bool,
pub config: CharacterConfig,
pub ground_body_index: Option<usize>,
pub platform_velocity: Vec3Fix,
}Expand description
Kinematic character controller
Fields§
§position: Vec3FixCurrent position (capsule center)
velocity: Vec3FixCurrent velocity
grounded: boolWhether the character is on the ground
config: CharacterConfigConfiguration
ground_body_index: Option<usize>Index of the ground body (for moving platform support)
platform_velocity: Vec3FixVelocity inherited from the moving platform
Implementations§
Source§impl CharacterController
impl CharacterController
Sourcepub const fn new(position: Vec3Fix, config: CharacterConfig) -> Self
pub const fn new(position: Vec3Fix, config: CharacterConfig) -> Self
Create a new character controller at the given position
Sourcepub fn new_default(position: Vec3Fix) -> Self
pub fn new_default(position: Vec3Fix) -> Self
Create with default config
Sourcepub fn feet_position(&self) -> Vec3Fix
pub fn feet_position(&self) -> Vec3Fix
Get the bottom of the capsule (feet position)
Sourcepub fn move_and_slide(
&mut self,
displacement: Vec3Fix,
bodies: &[RigidBody],
sdf_colliders: &[SdfCollider],
) -> MoveResult
pub fn move_and_slide( &mut self, displacement: Vec3Fix, bodies: &[RigidBody], sdf_colliders: &[SdfCollider], ) -> MoveResult
Move the character by the given displacement, sliding along colliders.
Uses the “collide and slide” algorithm:
- Try to move the full displacement
- On collision, project remaining displacement onto the collision plane
- Repeat up to
max_slidestimes
Static bodies are seen as spheres of the character’s radius at their
positions (see sweep_against_bodies); for the true shapes and the
world’s static colliders use crate::solver::PhysicsWorld::move_character.
Sourcepub fn compute_push_impulses(
&self,
bodies: &[RigidBody],
body_radius: Fix128,
) -> Vec<PushImpulse>
pub fn compute_push_impulses( &self, bodies: &[RigidBody], body_radius: Fix128, ) -> Vec<PushImpulse>
Compute push impulses for dynamic bodies overlapping the character.
Call this after move_and_slide to get impulses that should be applied
to nearby dynamic bodies. Apply them via body.apply_impulse_at().
Sourcepub const fn get_platform_velocity(&self) -> Vec3Fix
pub const fn get_platform_velocity(&self) -> Vec3Fix
Get the velocity of the platform the character is standing on
Sourcepub fn apply_gravity(&mut self, gravity: Vec3Fix, dt: Fix128)
pub fn apply_gravity(&mut self, gravity: Vec3Fix, dt: Fix128)
Integrate gravity into the velocity while airborne (v += g·dt).
Does not move the character; the position update happens in the controller’s own step / move path (before 1.2.0 the doc claimed “and update position”, which the code never did).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CharacterController
impl RefUnwindSafe for CharacterController
impl Send for CharacterController
impl Sync for CharacterController
impl Unpin for CharacterController
impl UnsafeUnpin for CharacterController
impl UnwindSafe for CharacterController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more