pub trait TnuaAction:
'static
+ Send
+ Sync {
type State: Default + Send + Sync;
const NAME: &'static str;
const VIOLATES_COYOTE_TIME: bool;
// Required methods
fn apply(
&self,
state: &mut Self::State,
ctx: TnuaActionContext<'_>,
lifecycle_status: TnuaActionLifecycleStatus,
motor: &mut TnuaMotor,
) -> TnuaActionLifecycleDirective;
fn initiation_decision(
&self,
ctx: TnuaActionContext<'_>,
being_fed_for: &Stopwatch,
) -> TnuaActionInitiationDirective;
// Provided method
fn proximity_sensor_cast_range(&self) -> Float { ... }
}
Expand description
A character movement command for performing special actions.
“Special” does not necessarily mean that special - even
jumping or crouching
are considered TnuaAction
s. Unlike basis - which is something constant - an action is
usually something more momentarily that has a flow.
The type that implements this trait is called the action input, and is expected to be overwritten each frame by the controller system of the game code - although unlike basis the input will probably be the exact same. Configuration is considered as part of the input. If the action 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 action.
Once type_name
becomes const
, this
will default to it. For now, just set it to the name of the type.
Sourceconst VIOLATES_COYOTE_TIME: bool
const VIOLATES_COYOTE_TIME: bool
Set this to true for actions that may launch the character into the air.
Required Associated Types§
Sourcetype State: Default + Send + Sync
type State: Default + Send + Sync
Data that the action can persist between frames.
The action will typically update this in its apply
. It has three purposes:
-
Store data that cannot be calculated on the spot. For example - the part of the jump the character is currently at.
-
Pass data from the action to Tnua’s internal mechanisms.
-
Inspect the action from game code systems, like an animation controlling system that needs to know which animation to play based on the action’s current state.
Required Methods§
Sourcefn apply(
&self,
state: &mut Self::State,
ctx: TnuaActionContext<'_>,
lifecycle_status: TnuaActionLifecycleStatus,
motor: &mut TnuaMotor,
) -> TnuaActionLifecycleDirective
fn apply( &self, state: &mut Self::State, ctx: TnuaActionContext<'_>, lifecycle_status: TnuaActionLifecycleStatus, motor: &mut TnuaMotor, ) -> TnuaActionLifecycleDirective
This is where the action affects the character’s motion.
This method gets called each frame to let the action control the TnuaMotor
that will
later move the character. Note that this happens the motor was set by the basis’
apply
. Here the action can modify some aspects of or even completely
overwrite what the basis did.
It can also update the state.
The returned value of this action determines whether or not the action will continue in the next frame.
Sourcefn initiation_decision(
&self,
ctx: TnuaActionContext<'_>,
being_fed_for: &Stopwatch,
) -> TnuaActionInitiationDirective
fn initiation_decision( &self, ctx: TnuaActionContext<'_>, being_fed_for: &Stopwatch, ) -> TnuaActionInitiationDirective
Decides whether the action can start.
The difference between rejecting the action here with
TnuaActionInitiationDirective::Reject
or TnuaActionInitiationDirective::Delay
and
approving it with TnuaActionInitiationDirective::Allow
only to do nothing in it and
terminate with TnuaActionLifecycleDirective::Finished
on the first frame, is that if
some other action is currently running, in the former that action will continue to be
active, while in the latter it’ll be cancelled into this new action - which, having being
immediately finished, will leave the controller with no active action, or with some third
action if there is one.
Provided Methods§
Sourcefn proximity_sensor_cast_range(&self) -> Float
fn proximity_sensor_cast_range(&self) -> Float
A value to configure the range of the ground proximity sensor according to the action’s needs.
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.