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§
Sourceconst NAME: &'static str
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§
Sourcetype State: Default + Send + Sync
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:
-
Store data that cannot be calculated on the spot. For example - a timer for tracking coyote time.
-
Pass data from the basis to the action (or to Tnua’s internal mechanisms)
-
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§
Sourcefn apply(
&self,
state: &mut Self::State,
ctx: TnuaBasisContext<'_>,
motor: &mut TnuaMotor,
)
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.
Sourcefn proximity_sensor_cast_range(&self, state: &Self::State) -> Float
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.
Sourcefn displacement(&self, state: &Self::State) -> Option<Vector3>
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.
Sourcefn effective_velocity(&self, state: &Self::State) -> Vector3
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.
Sourcefn vertical_velocity(&self, state: &Self::State) -> Float
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
.
Sourcefn neutralize(&mut self)
fn neutralize(&mut self)
Nullify the fields of the basis that represent user input.
Sourcefn is_airborne(&self, state: &Self::State) -> bool
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.
Sourcefn violate_coyote_time(&self, state: &mut Self::State)
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.