pub struct TnuaController { /* private fields */ }
Expand description
The main component used for interaction with the controls and animation code.
Every frame, the game code should feed input this component on every controlled entity. What should be fed is:
-
A basis - this is the main movement command - usually
TnuaBuiltinWalk
, but there can be others. It is the game code’s responsibility to ensure only one basis is fed at any given time, because basis can hold state and replacing the basis type restarts the state.Refer to the documentation of the implementors of
TnuaBasis
for more information. -
Zero or more actions - these are movements like jumping, dashing, crouching, etc. Multiple actions can be fed, but only one can be active at any given moment. Unlike basis, there is a smart mechanism for deciding which action to use and which to discard, so it is safe to feed many actions at the same frame.
Refer to the documentation of the implementors of
TnuaAction
for more information.
Without TnuaControllerPlugin
this component will not do anything.
Implementations§
Source§impl TnuaController
impl TnuaController
Sourcepub fn basis<B: TnuaBasis>(&mut self, basis: B)
pub fn basis<B: TnuaBasis>(&mut self, basis: B)
Feed a basis - the main movement command - with its default name.
Sourcepub fn named_basis<B: TnuaBasis>(&mut self, name: &'static str, basis: B)
pub fn named_basis<B: TnuaBasis>(&mut self, name: &'static str, basis: B)
Feed a basis - the main movement command - with a custom name.
This should only be used if the same basis type needs to be used with different names to
allow, for example, different animations. Otherwise prefer to use the default name with
basis
.
Sourcepub fn neutralize_basis(&mut self)
pub fn neutralize_basis(&mut self)
Instruct the basis to pretend the user provided no input this frame.
The exact meaning is defined in the basis’ neutralize
method,
but generally it means that fields that typically come from a configuration will not be
touched, and only fields that are typically set by user input get nullified.
Sourcepub fn basis_name(&self) -> Option<&'static str>
pub fn basis_name(&self) -> Option<&'static str>
The name of the currently running basis.
When using the basis with it’s default name, prefer to match this against
TnuaBasis::NAME
and not against a string literal.
Sourcepub fn dynamic_basis(&self) -> Option<&dyn DynamicBasis>
pub fn dynamic_basis(&self) -> Option<&dyn DynamicBasis>
A dynamic accessor to the currently running basis.
Sourcepub fn concrete_basis<B: TnuaBasis>(&self) -> Option<(&B, &B::State)>
pub fn concrete_basis<B: TnuaBasis>(&self) -> Option<(&B, &B::State)>
The currently running basis, together with its state.
This is mainly useful for animation. When multiple basis types are used in the game,
basis_name
be used to determine the type of the current basis first,
to avoid having to try multiple downcasts.
Sourcepub fn concrete_basis_mut<B: TnuaBasis>(
&mut self,
) -> Option<(&B, &mut B::State)>
pub fn concrete_basis_mut<B: TnuaBasis>( &mut self, ) -> Option<(&B, &mut B::State)>
The currently running basis, together with its state, as mutable. Useful if you need to touch the state of a running action to respond to game events.
Sourcepub fn action<A: TnuaAction>(&mut self, action: A)
pub fn action<A: TnuaAction>(&mut self, action: A)
Feed an action with its default name.
Sourcepub fn named_action<A: TnuaAction>(&mut self, name: &'static str, action: A)
pub fn named_action<A: TnuaAction>(&mut self, name: &'static str, action: A)
Feed an action with a custom name.
This should only be used if the same action type needs to be used with different names to
allow, for example, different animations. Otherwise prefer to use the default name with
action
.
Sourcepub fn action_name(&self) -> Option<&'static str>
pub fn action_name(&self) -> Option<&'static str>
The name of the currently running action.
When using an action with it’s default name, prefer to match this against
TnuaAction::NAME
and not against a string literal.
Sourcepub fn dynamic_action(&self) -> Option<&dyn DynamicAction>
pub fn dynamic_action(&self) -> Option<&dyn DynamicAction>
A dynamic accessor to the currently running action.
Sourcepub fn concrete_action<A: TnuaAction>(&self) -> Option<(&A, &A::State)>
pub fn concrete_action<A: TnuaAction>(&self) -> Option<(&A, &A::State)>
The currently running action, together with its state.
This is mainly useful for animation. When multiple action types are used in the game,
action_name
be used to determine the type of the current action
first, to avoid having to try multiple downcasts.
Sourcepub fn concrete_action_mut<A: TnuaAction>(
&mut self,
) -> Option<(&A, &mut A::State)>
pub fn concrete_action_mut<A: TnuaAction>( &mut self, ) -> Option<(&A, &mut A::State)>
The currently running action, together with its state, as mutable. Useful if you need to touch the state of a running action to respond to game events.
If the action is replaced, the state will be lost. If you need to keep the state, you should store it separately.
Sourcepub fn action_flow_status(&self) -> &TnuaActionFlowStatus
pub fn action_flow_status(&self) -> &TnuaActionFlowStatus
Indicator for the state and flow of movement actions.
Query this every frame to keep track of the actions. For air actions,
TnuaAirActionsTracker
is easier to use
(and uses this behind the scenes)
The benefits of this over querying action_name
every frame are:
action_flow_status
can indicate when the same action has been fed again immediately after stopping or cancelled into itself.action_flow_status
shows anActionEnded
when the action is no longer fed, even if the action is still active (termination sequence)
Sourcepub fn is_airborne(&self) -> Result<bool, TnuaControllerHasNoBasis>
pub fn is_airborne(&self) -> Result<bool, TnuaControllerHasNoBasis>
Checks if the character is currently airborne.
The check is done based on the basis, and is equivalent to getting the controller’s
dynamic_basis
and checking its
is_airborne
method.
Trait Implementations§
Source§impl Component for TnuaController
Required Components: TnuaMotor
, TnuaRigidBodyTracker
, TnuaProximitySensor
.
impl Component for TnuaController
Required Components: TnuaMotor
, TnuaRigidBodyTracker
, TnuaProximitySensor
.
A component’s Required Components are inserted whenever it is inserted. Note that this will also insert the required components of the required components, recursively, in depth-first order.
Source§const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table
Source§fn register_required_components(
requiree: ComponentId,
components: &mut Components,
storages: &mut Storages,
required_components: &mut RequiredComponents,
inheritance_depth: u16,
)
fn register_required_components( requiree: ComponentId, components: &mut Components, storages: &mut Storages, required_components: &mut RequiredComponents, inheritance_depth: u16, )
Source§fn register_component_hooks(hooks: &mut ComponentHooks)
fn register_component_hooks(hooks: &mut ComponentHooks)
ComponentHooks
.Source§impl Default for TnuaController
impl Default for TnuaController
Source§fn default() -> TnuaController
fn default() -> TnuaController
Auto Trait Implementations§
impl Freeze for TnuaController
impl !RefUnwindSafe for TnuaController
impl Send for TnuaController
impl Sync for TnuaController
impl Unpin for TnuaController
impl !UnwindSafe for TnuaController
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
Source§fn register_required_components(
components: &mut Components,
storages: &mut Storages,
required_components: &mut RequiredComponents,
)
fn register_required_components( components: &mut Components, storages: &mut Storages, required_components: &mut RequiredComponents, )
Bundle
.Source§fn get_component_ids(
components: &Components,
ids: &mut impl FnMut(Option<ComponentId>),
)
fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self
using default()
.
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more