pub struct TnuaSimpleAirActionsCounter { /* private fields */ }
Expand description
A simple counter that counts together all the air actions a character is able to perform.
It’s update
must be called every frame.
Implementations§
Source§impl TnuaSimpleAirActionsCounter
impl TnuaSimpleAirActionsCounter
Sourcepub fn update(&mut self, controller: &TnuaController)
pub fn update(&mut self, controller: &TnuaController)
Call this every frame to track the air actions.
Sourcepub fn reset_count_to(&mut self, count: usize)
pub fn reset_count_to(&mut self, count: usize)
Resets the air actions counter to a specific count, excluding the current action.
This method allows you to manually set the count of air actions (excluding the current action) to a specified value. Use this when you need to synchronize or initialize the air actions count to a specific state.
§Arguments
count
- The new count to set for air actions, excluding the current action.
§Example
use bevy_tnua::control_helpers::TnuaSimpleAirActionsCounter;
let mut air_actions_counter = TnuaSimpleAirActionsCounter::default();
// Reset the air actions count to 3 (excluding the current action). should also be updated as stated in TnuaAirActionsTracker
air_actions_counter.reset_count_to(3);
Sourcepub fn get_count_mut(&mut self) -> Option<&mut usize>
pub fn get_count_mut(&mut self) -> Option<&mut usize>
Obtain a mutable reference to the air counter.
This can be use to modify the air counter while the player is in the air - for example, restoring an air jump when they pick up a floating token.
When it fits the usage, prefer reset_count
which is simpler.
get_count_mut
should be used for more complex cases, e.g. when the player is allowed
multiple air jumps, but only one jump gets restored per token.
Note that:
- When the character is grounded, this method returns
None
. This is only for mutating the counter while the character is airborne. - When the character jumps from the ground, or starts a free fall, the counter is one - not zero. Setting the counter to 0 will mean that the next air jump will actually be treated as a ground jump - and they’ll get another air jump in addition to it. This is usually not the desired behavior.
- Changing the action counter returned by this method will not affect the value
air_count_for
returns for an action that continues to be fed.
Sourcepub fn reset_count(&mut self)
pub fn reset_count(&mut self)
Resets the air actions counter.
This is equivalent to setting the counter to 1 using:
if let Some(count) = air_actions_counter.get_count_mut() {
*count = 1;
}
The reason it is set to 1 and not 0 is that when the character jumps from the ground or
starts a free fall the counter is 1 - and this is what one would usually want to reset to.
Having a counter of 0 means that the character is grounded - but in that case
get_count_mut
will return None
and the counter will not change.
Sourcepub fn air_count_for(&self, action_name: &str) -> usize
pub fn air_count_for(&self, action_name: &str) -> usize
Calculate the “air number” of an action.
The air number of a ground action is 0. The first air jump (double jump) as an air number of 1, the second (triple jump) has an air number of 2 and so on. Other air actions (like air dashes) are counted together with the jumps.
Use this number to:
- Determine if the action is allowed.
- Optionally change the action’s parameters as the air number progresses.
Note that the action name is important, because Tnua relies on constant feed of some
actions. As long as you pass the correct name, the number will not change while the action
continues to be fed. The correct name is TnuaAction::NAME
when using
TnuaController::action
or the first argument when using
TnuaController::named_action
.
Trait Implementations§
Source§impl Component for TnuaSimpleAirActionsCounter
impl Component for TnuaSimpleAirActionsCounter
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 TnuaSimpleAirActionsCounter
impl Default for TnuaSimpleAirActionsCounter
Source§fn default() -> TnuaSimpleAirActionsCounter
fn default() -> TnuaSimpleAirActionsCounter
Auto Trait Implementations§
impl Freeze for TnuaSimpleAirActionsCounter
impl RefUnwindSafe for TnuaSimpleAirActionsCounter
impl Send for TnuaSimpleAirActionsCounter
impl Sync for TnuaSimpleAirActionsCounter
impl Unpin for TnuaSimpleAirActionsCounter
impl UnwindSafe for TnuaSimpleAirActionsCounter
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