bevy_tnua

Trait TnuaBasis

Source
pub trait TnuaBasis:
    'static
    + Send
    + Sync {
    type State: Default + Send + Sync;

    const NAME: &'static str;

    // Required methods
    fn apply(
        &self,
        state: &mut Self::State,
        ctx: TnuaBasisContext<'_>,
        motor: &mut TnuaMotor,
    );
    fn proximity_sensor_cast_range(&self, state: &Self::State) -> Float;
    fn displacement(&self, state: &Self::State) -> Option<Vector3>;
    fn effective_velocity(&self, state: &Self::State) -> Vector3;
    fn vertical_velocity(&self, state: &Self::State) -> Float;
    fn neutralize(&mut self);
    fn is_airborne(&self, state: &Self::State) -> bool;
    fn violate_coyote_time(&self, state: &mut Self::State);
}
Expand description

The main movement command of a character.

A basis handles the character’s motion when the user is not feeding it any input, or when it just moves around without doing anything special. A simple game would only need once basis - TnuaBuiltinWalk - but more complex games can have bases for things like swimming or driving.

The type that implements this trait is called the basis input, and is expected to be overwritten each frame by the controller system of the game code. Configuration is considered as part of the input. If the basis needs to persist data between frames it must keep it in its state.

Required Associated Constants§

Source

const NAME: &'static str

The default name of the basis.

Once type_name becomes const, this will default to it. For now, just set it to the name of the type.

Required Associated Types§

Source

type State: Default + Send + Sync

Data that the basis can persist between frames.

The basis will typically update this in its apply. It has three purposes:

  1. Store data that cannot be calculated on the spot. For example - a timer for tracking coyote time.

  2. Pass data from the basis to the action (or to Tnua’s internal mechanisms)

  3. Inspect the basis from game code systems, like an animation controlling system that needs to know which animation to play based on the basis’ current state.

Required Methods§

Source

fn apply( &self, state: &mut Self::State, ctx: TnuaBasisContext<'_>, motor: &mut TnuaMotor, )

This is where the basis affects the character’s motion.

This method gets called each frame to let the basis control the TnuaMotor that will later move the character.

Note that after the motor is set in this method, if there is an action going on, the action’s apply will also run and typically change some of the things the basis did to the motor.

It can also update the state.

Source

fn proximity_sensor_cast_range(&self, state: &Self::State) -> Float

A value to configure the range of the ground proximity sensor according to the basis’ needs.

Source

fn displacement(&self, state: &Self::State) -> Option<Vector3>

The displacement of the character from where the basis wants it to be.

This is a query method, used by the action to determine what the basis thinks.

Source

fn effective_velocity(&self, state: &Self::State) -> Vector3

The velocity of the character, relative the what the basis considers its frame of reference.

This is a query method, used by the action to determine what the basis thinks.

Source

fn vertical_velocity(&self, state: &Self::State) -> Float

The vertical velocity the character requires to stay the same height if it wants to move in effective_velocity.

Source

fn neutralize(&mut self)

Nullify the fields of the basis that represent user input.

Source

fn is_airborne(&self, state: &Self::State) -> bool

Can be queried by an action to determine if the character should be considered “in the air”.

This is a query method, used by the action to determine what the basis thinks.

Source

fn violate_coyote_time(&self, state: &mut Self::State)

If the basis is at coyote time - finish the coyote time.

This will be called automatically by Tnua, if the controller runs an action that violated coyote time, so that a long coyote time will not allow, for example, unaccounted air jumps.

If the character is fully grounded, this method must not change that.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl TnuaBasis for TnuaBuiltinWalk

Source§

const NAME: &'static str = "TnuaBuiltinWalk"

Source§

type State = TnuaBuiltinWalkState