bevy_tnua::builtins

Struct TnuaBuiltinWalk

Source
pub struct TnuaBuiltinWalk {
Show 14 fields pub desired_velocity: Vector3, pub desired_forward: Option<Dir3>, pub float_height: Float, pub cling_distance: Float, pub spring_strength: Float, pub spring_dampening: Float, pub acceleration: Float, pub air_acceleration: Float, pub coyote_time: Float, pub free_fall_extra_gravity: Float, pub tilt_offset_angvel: Float, pub tilt_offset_angacl: Float, pub turning_angvel: Float, pub max_slope: Float,
}
Expand description

The most common basis - walk around as a floating capsule.

This basis implements the floating capsule character controller explained in https://youtu.be/qdskE8PJy6Q. It controls both the floating and the movement. Most of its fields have sane defaults, except:

  • float_height - this field defaults to 0.0, which means the character will not float. Set it to be higher than the distance from the center of the entity to the bottom of the collider.

  • desired_velocity - while leaving this as as the default Vector3::ZERO, doing so would mean that the character will not move.

  • desired_forward - leaving this is the default None will mean that Tnua will not attempt to fix the character’s rotation along the up axis.

    This is fine if rotation along the up axis is locked (Rapier and Avian only support locking cardinal axes, but the up direction is based on the gravity which means it defaults to the Y axis so it usually works out).

    This is also fine for 2D games (or games with 3D graphics and 2D physics) played from side view where the physics engine cannot rotate the character along the up axis.

    But if the physics engine is free to rotate the character’s rigid body along the up axis, leaving desired_forward as the default Vector3::ZERO may cause the character to spin uncontrollably when it contacts other colliders. Unless, of course, some other mechanism prevents that.

Fields§

§desired_velocity: Vector3

The direction (in the world space) and speed to accelerate to.

Tnua assumes that this vector is orthogonal to the up dierction.

§desired_forward: Option<Dir3>

If non-zero, Tnua will rotate the character so that its negative Z will face in that direction.

Tnua assumes that this vector is orthogonal to the up direction.

§float_height: Float

The height at which the character will float above ground at rest.

Note that this is the height of the character’s center of mass - not the distance from its collision mesh.

To make a character crouch, instead of altering this field, prefer to use the TnuaBuiltinCrouch action.

§cling_distance: Float

Extra distance above the float_height where the spring is still in effect.

When the character is at at most this distance above the float_height, the spring force will kick in and move it to the float height - even if that means pushing it down. If the character is above that distance above the float_height, Tnua will consider it to be in the air.

§spring_strength: Float

The force that pushes the character to the float height.

The actual force applied is in direct linear relationship to the displacement from the float_height.

§spring_dampening: Float

A force that slows down the characters vertical spring motion.

The actual dampening is in direct linear relationship to the vertical velocity it tries to dampen.

Note that as this approaches 2.0, the character starts to shake violently and eventually get launched upward at great speed.

§acceleration: Float

The acceleration for horizontal movement.

Note that this is the acceleration for starting the horizontal motion and for reaching the top speed. When braking or changing direction the acceleration is greater, up to 2 times acceleration when doing a 180 turn.

§air_acceleration: Float

The acceleration for horizontal movement while in the air.

Set to 0.0 to completely disable air movement.

§coyote_time: Float

The time, in seconds, the character can still jump after losing their footing.

§free_fall_extra_gravity: Float

Extra gravity for free fall (fall that’s not initiated by a jump or some other action that provides its own fall gravity)

NOTE: This force will be added to the normal gravity.

NOTE: If the parameter set to this option is too low, the character may be able to run up a slope and “jump” potentially even higher than a regular jump, even without pressing the jump button.

§tilt_offset_angvel: Float

The maximum angular velocity used for keeping the character standing upright.

NOTE: The character’s rotation can also be locked to prevent it from being tilted, in which case this paramter is redundant and can be set to 0.0.

§tilt_offset_angacl: Float

The maximum angular acceleration used for reaching tilt_offset_angvel.

NOTE: The character’s rotation can also be locked to prevent it from being tilted, in which case this paramter is redundant and can be set to 0.0.

§turning_angvel: Float

The maximum angular velocity used for turning the character when the direction changes.

§max_slope: Float

The maximum slope, in radians, that the character can stand on without slipping.

Implementations§

Source§

impl TnuaBuiltinWalk

Source

pub fn spring_force( &self, state: &TnuaBuiltinWalkState, ctx: &TnuaBasisContext<'_>, spring_offset: Float, ) -> TnuaVelChange

Calculate the vertical spring force that this basis would need to apply assuming its vertical distance from the vertical distance it needs to be at equals the spring_offset argument.

Note: this is exposed so that actions like TnuaBuiltinCrouch may rely on it.

Trait Implementations§

Source§

impl Clone for TnuaBuiltinWalk

Source§

fn clone(&self) -> TnuaBuiltinWalk

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TnuaBuiltinWalk

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TnuaBuiltinWalk

Source§

fn default() -> Self

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

impl TnuaBasis for TnuaBuiltinWalk

Source§

const NAME: &'static str = "TnuaBuiltinWalk"

The default name of the basis. Read more
Source§

type State = TnuaBuiltinWalkState

Data that the basis can persist between frames. Read more
Source§

fn apply( &self, state: &mut Self::State, ctx: TnuaBasisContext<'_>, motor: &mut TnuaMotor, )

This is where the basis affects the character’s motion. Read more
Source§

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

fn displacement(&self, state: &Self::State) -> Option<Vector3>

The displacement of the character from where the basis wants it to be. Read more
Source§

fn effective_velocity(&self, state: &Self::State) -> Vector3

The velocity of the character, relative the what the basis considers its frame of reference. Read more
Source§

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

fn neutralize(&mut self)

Nullify the fields of the basis that represent user input.
Source§

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”. Read more
Source§

fn violate_coyote_time(&self, state: &mut Self::State)

If the basis is at coyote time - finish the coyote time. 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

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

Source§

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

Convert 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>

Convert 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)

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

Convert &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
where T: Any + Send + Sync,

Source§

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

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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,