Skip to main content

FirstPersonController

Struct FirstPersonController 

Source
pub struct FirstPersonController {
    pub body: Body3D,
    pub previous: Vec3,
    /* private fields */
}
Expand description

Allocation-free optional helper. Spawn outside static solids; initial overlaps are not depenetrated. Body movement resolves X, Z then Y, using Body3D sweeps.

Fields§

§body: Body3D

Game-accessible swept body. External edits must retain Body3D invariants.

§previous: Vec3

Previous center for interpolation. Use teleport for discontinuous movement.

Implementations§

Source§

impl FirstPersonController

Source

pub fn new( position: Vec3, size: Vec3, config: FirstPersonConfig, ) -> Result<Self, FirstPersonError>

Creates a controller from center/full body dimensions. Rejects invalid config and nonfinite/nonpositive body dimensions before constructing it.

Source

pub fn config(&self) -> &FirstPersonConfig

Current validated configuration.

Source

pub fn set_config( &mut self, config: FirstPersonConfig, ) -> Result<(), FirstPersonError>

Reconfigures atomically, clamping pitch and clearing pending jump/grace state.

Source

pub fn yaw(&self) -> f32

Horizontal yaw in radians, positive turns toward +X from the -Z heading.

Source

pub fn pitch(&self) -> f32

Vertical pitch in radians, positive looks up.

Source

pub fn set_look(&mut self, yaw: f32, pitch: f32) -> Result<(), FirstPersonError>

Sets finite angles, wrapping yaw and clamping pitch. Failure changes nothing.

Source

pub fn teleport(&mut self, position: Vec3) -> Result<(), FirstPersonError>

Resets movement, contact, interpolation and pending jumps at a game-chosen position. Keeps look angles; checkpoint/spawn validity remains game policy.

Source

pub fn step(&mut self, input: FirstPersonInput, dt: f32, solids: &[Aabb3])

Applies one fixed tick. Panics for invalid input or nonfinite/negative dt. A zero dt applies look only, retaining movement/contact/interpolation state. Consume press edges and relative motion once afterward, including catch-up.

Source

pub fn camera(&self, alpha: f32) -> Camera3D

Eye camera with interpolated position and latest (uninterpolated) angles. Alpha must be finite in [0, 1]. Teleport removes interpolation across resets.

Trait Implementations§

Source§

impl Clone for FirstPersonController

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FirstPersonController

Source§

impl Debug for FirstPersonController

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Component for T
where T: Send + Sync + 'static,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.