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 defaultVector3::ZERO
, doing so would mean that the character will not move. -
desired_forward
- leaving this is the defaultNone
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 defaultVector3::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
impl TnuaBuiltinWalk
Sourcepub fn spring_force(
&self,
state: &TnuaBuiltinWalkState,
ctx: &TnuaBasisContext<'_>,
spring_offset: Float,
) -> TnuaVelChange
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
impl Clone for TnuaBuiltinWalk
Source§fn clone(&self) -> TnuaBuiltinWalk
fn clone(&self) -> TnuaBuiltinWalk
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TnuaBuiltinWalk
impl Debug for TnuaBuiltinWalk
Source§impl Default for TnuaBuiltinWalk
impl Default for TnuaBuiltinWalk
Source§impl TnuaBasis for TnuaBuiltinWalk
impl TnuaBasis for TnuaBuiltinWalk
Source§type State = TnuaBuiltinWalkState
type State = TnuaBuiltinWalkState
Source§fn apply(
&self,
state: &mut Self::State,
ctx: TnuaBasisContext<'_>,
motor: &mut TnuaMotor,
)
fn apply( &self, state: &mut Self::State, ctx: TnuaBasisContext<'_>, motor: &mut TnuaMotor, )
Source§fn proximity_sensor_cast_range(&self, _state: &Self::State) -> Float
fn proximity_sensor_cast_range(&self, _state: &Self::State) -> Float
Source§fn displacement(&self, state: &Self::State) -> Option<Vector3>
fn displacement(&self, state: &Self::State) -> Option<Vector3>
Source§fn effective_velocity(&self, state: &Self::State) -> Vector3
fn effective_velocity(&self, state: &Self::State) -> Vector3
Source§fn vertical_velocity(&self, state: &Self::State) -> Float
fn vertical_velocity(&self, state: &Self::State) -> Float
effective_velocity
.Source§fn neutralize(&mut self)
fn neutralize(&mut self)
Source§fn is_airborne(&self, state: &Self::State) -> bool
fn is_airborne(&self, state: &Self::State) -> bool
Source§fn violate_coyote_time(&self, state: &mut Self::State)
fn violate_coyote_time(&self, state: &mut Self::State)
Auto Trait Implementations§
impl Freeze for TnuaBuiltinWalk
impl RefUnwindSafe for TnuaBuiltinWalk
impl Send for TnuaBuiltinWalk
impl Sync for TnuaBuiltinWalk
impl Unpin for TnuaBuiltinWalk
impl UnwindSafe for TnuaBuiltinWalk
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<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