pub struct CharacterController {
pub position: Point3<f32>,
pub velocity: Vector3<f32>,
pub yaw: f32,
pub pitch: f32,
pub height: f32,
pub radius: f32,
pub eye_fraction: f32,
pub on_ground: bool,
pub walk_speed: f32,
pub run_speed: f32,
pub jump_speed: f32,
pub gravity: f32,
}Expand description
First-person character controller.
position is the foot point — the lowest Y the player occupies.
Eyes sit at position.y + height * eye_fraction.
Fields§
§position: Point3<f32>Foot position (Y = the floor the player stands on).
velocity: Vector3<f32>Current velocity in m/s.
Horizontal components are overwritten by input every tick. The vertical component accumulates gravity between frames.
yaw: f32Horizontal look direction, radians. 0 = facing −Z (into the screen). Increases clockwise when viewed from above.
pitch: f32Vertical look angle, radians. Clamped to ±~84°.
height: f32Standing height in metres.
radius: f32Horizontal half-width of the player AABB (metres).
eye_fraction: f32Fraction of height at which the eye / camera sits (default 0.86).
on_ground: booltrue when the character is resting on a solid surface.
walk_speed: f32Walk speed (m/s, used when InputState::sprint is false).
run_speed: f32Run / sprint speed (m/s).
jump_speed: f32Upward velocity applied on jump (m/s).
gravity: f32Gravitational acceleration (m/s², positive = downward).
Implementations§
Source§impl CharacterController
impl CharacterController
Sourcepub fn new(pos: Point3<f32>) -> Self
pub fn new(pos: Point3<f32>) -> Self
Create a controller with sensible defaults.
The player spawns at pos with feet touching the floor (Y=pos.y).
Call tick once per frame to advance the simulation.
Sourcepub fn forward_flat(&self) -> Vector3<f32>
pub fn forward_flat(&self) -> Vector3<f32>
Unit vector pointing forward in the horizontal plane (ignores pitch).
Sourcepub fn right_flat(&self) -> Vector3<f32>
pub fn right_flat(&self) -> Vector3<f32>
Unit vector pointing right in the horizontal plane.
Sourcepub fn eye_position(&self) -> Point3<f32>
pub fn eye_position(&self) -> Point3<f32>
Camera / eye position in world space.
Sourcepub fn look_target(&self) -> Point3<f32>
pub fn look_target(&self) -> Point3<f32>
Point the camera should target (eye_position + look_dir).
Sourcepub fn apply_to_camera(&self, engine: &mut K3dengine)
pub fn apply_to_camera(&self, engine: &mut K3dengine)
Write the eye position and look target into the engine camera.
Sourcepub fn tick(&mut self, input: &InputState, dt: f32, colliders: &[[f32; 6]])
pub fn tick(&mut self, input: &InputState, dt: f32, colliders: &[[f32; 6]])
Advance one frame of simulation.
§Arguments
input— this frame’s input (direction, look deltas, jump, sprint)dt— elapsed time in seconds (clamp to ≤ 0.05 to avoid tunnelling on lag spikes)colliders— world geometry as[min_x, min_y, min_z, max_x, max_y, max_z]boxes. Include floor, ceiling, and all walls.
Trait Implementations§
Source§impl Clone for CharacterController
impl Clone for CharacterController
Source§fn clone(&self) -> CharacterController
fn clone(&self) -> CharacterController
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto 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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.