Skip to main content

CharacterController

Struct CharacterController 

Source
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: Vec3Fix

Current position (capsule center)

§velocity: Vec3Fix

Current velocity

§grounded: bool

Whether the character is on the ground

§config: CharacterConfig

Configuration

§ground_body_index: Option<usize>

Index of the ground body (for moving platform support)

§platform_velocity: Vec3Fix

Velocity inherited from the moving platform

Implementations§

Source§

impl CharacterController

Source

pub const fn new(position: Vec3Fix, config: CharacterConfig) -> Self

Create a new character controller at the given position

Source

pub fn new_default(position: Vec3Fix) -> Self

Create with default config

Source

pub fn feet_position(&self) -> Vec3Fix

Get the bottom of the capsule (feet position)

Source

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:

  1. Try to move the full displacement
  2. On collision, project remaining displacement onto the collision plane
  3. Repeat up to max_slides times

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.

Source

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().

Source

pub const fn get_platform_velocity(&self) -> Vec3Fix

Get the velocity of the platform the character is standing on

Source

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§

Source§

impl Debug for CharacterController

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.