TnuaController

Struct TnuaController 

Source
pub struct TnuaController<S: TnuaScheme> {
    pub basis: S::Basis,
    pub basis_config: Option<<S::Basis as TnuaBasis>::Config>,
    pub basis_memory: <S::Basis as TnuaBasis>::Memory,
    pub current_action: Option<S::ActionState>,
    /* private fields */
}
Expand description

The main component used for interaction with the controls and animation code (needs a TnuaConfig)

Every frame, the game code should invoke initiate_action_feeding and then 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. The controller’s basis is takens from the scheme (the generic argument). Controlling it is done by modifying the basis field of the controller.

    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. Actions are also defined in the scheme, and can be fed using the action method.

    Refer to the documentation of the implementors of TnuaAction for more information.

Without TnuaControllerPlugin of the same scheme this component will not do anything.

Fields§

§basis: S::Basis

Input for the basis - the main movement command.

§basis_config: Option<<S::Basis as TnuaBasis>::Config>

A copy of the basis’ configuration from the asset.

§basis_memory: <S::Basis as TnuaBasis>::Memory

Kept by the basis itself - but user code may modify if it knows what it`s doing.

§current_action: Option<S::ActionState>

The full state of the currently running action.

Be careful when touching that:

  • Changing the input and even config is usually fine.
  • Only change the state if you know what you’re doing.
  • Never change the actual variant.

Implementations§

Source§

impl<S: TnuaScheme> TnuaController<S>

Source

pub fn basis_access( &self, ) -> Result<TnuaBasisAccess<'_, S::Basis>, TnuaControllerHasNotPulledConfiguration>

Access to the entire basis state. This is what the basis capabilities usually use.

Source

pub fn initiate_action_feeding(&mut self)

Must be called each frame before feeding the actions (unless action) is never used)

Source

pub fn action(&mut self, action: S)

Feed an action.

This is used in pull fashion - a system (or set of systems) that checks the state of the playter input (or of some NPC controller) and can feed the action every frame its still on. This system must start by calling initiate_action_feeding.

For pushing actions, use one of the other action_* methods.

Source

pub fn action_trigger(&mut self, action: S)

Trigger an action in a push fashion. The action must be one that handles its own duration.

This means that actions like TnuaBuiltinCrouch cannot be used with this method - the character will rise after one frame of starting to crouch. Actions like ’TnuaBuiltinDash` are okay because the dash will only end when the motion itself is finished.

Source

pub fn action_interrupt(&mut self, action: S)

Similar to action_trigger, but can override other action contenders and other action feeding methods cannot override it.

Source

pub fn action_start(&mut self, action: S)

Trigger an action in a push fashion. The action will continue until action_end is called - or until the motion itself is finished.

Source

pub fn action_end(&mut self, action: S::ActionDiscriminant)

End an action that started with action_start

Source

pub fn prolong_action(&mut self)

Re-feed the same action that is currently active.

This is useful when matching on current_action and wanting to continue feeding the exact same action with the exact same input without having to

Source

pub fn action_discriminant(&self) -> Option<S::ActionDiscriminant>

The discriminant of the currently running action.

Source

pub fn action_flow_status(&self) -> &TnuaActionFlowStatus<S::ActionDiscriminant>

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_discriminant 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 an ActionEnded when the action is no longer fed, even if the action is still active (termination sequence)
Source

pub fn up_direction(&self) -> Option<Dir3>

Returns the direction considered as up.

Note that the up direction is based on gravity, as reported by TnuaRigidBodyTracker::gravity, and that it’d typically be one frame behind since it gets updated in the same system that applies the controller logic. If this is unacceptable, consider using TnuaRigidBodyTracker::gravity directly or deducing the up direction via different means.

Source§

impl<S: TnuaScheme> TnuaController<S>

Source

pub fn is_airborne( &self, ) -> Result<bool, TnuaControllerHasNotPulledConfiguration>

Checks if the character is currently airborne.

The check is done based on the basis, and is equivalent to getting the controller’s basis_access and using TnuaBasisWithGround::is_airborne on it.

Trait Implementations§

Source§

impl<S: TnuaScheme> Component for TnuaController<S>
where Self: Send + Sync + 'static,

Required Components: TnuaMotor, TnuaRigidBodyTracker.

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

A constant indicating the storage type used for this component.
Source§

type Mutability = Mutable

A marker type to assist Bevy with determining if this component is mutable, or immutable. Mutable components will have Component<Mutability = Mutable>, while immutable components will instead have Component<Mutability = Immutable>. Read more
Source§

fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )

Registers required components. Read more
Source§

fn clone_behavior() -> ComponentCloneBehavior

Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
Source§

fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_add ComponentHook for this Component if one is defined.
Source§

fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_insert ComponentHook for this Component if one is defined.
Source§

fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_replace ComponentHook for this Component if one is defined.
Source§

fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_remove ComponentHook for this Component if one is defined.
Source§

fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_despawn ComponentHook for this Component if one is defined.
Source§

fn map_entities<E>(_this: &mut Self, _mapper: &mut E)
where E: EntityMapper,

Maps the entities on this component using the given EntityMapper. This is used to remap entities in contexts like scenes and entity cloning. When deriving Component, this is populated by annotating fields containing entities with #[entities] Read more
Source§

impl<S: TnuaScheme> Default for TnuaController<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<C> Bundle for C
where C: Component,

Source§

fn component_ids( components: &mut ComponentsRegistrator<'_>, ids: &mut impl FnMut(ComponentId), )

Source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

Gets this Bundle’s component ids. This will be None if the component has not been registered.
Source§

impl<C> BundleFromComponents for C
where C: Component,

Source§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &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)

Converts &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> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<C> DynamicBundle for C
where C: Component,

Source§

type Effect = ()

An operation on the entity that happens after inserting this bundle.
Source§

unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect

Moves the components out of the bundle. Read more
Source§

unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )

Applies the after-effects of spawning this bundle. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,