movement affected by walking in water
This commit is contained in:
@@ -50,6 +50,10 @@ pub struct PlayerMovement {
|
||||
#[reflect(Component)]
|
||||
pub struct MovementAcceleration(Scalar);
|
||||
|
||||
#[derive(Component, Reflect)]
|
||||
#[reflect(Component)]
|
||||
pub struct MovementSpeedFactor(pub f32);
|
||||
|
||||
/// The strength of a jump.
|
||||
#[derive(Component, Reflect)]
|
||||
#[reflect(Component)]
|
||||
@@ -85,6 +89,7 @@ pub struct MovementBundle {
|
||||
acceleration: MovementAcceleration,
|
||||
jump_impulse: JumpImpulse,
|
||||
max_slope_angle: MaxSlopeAngle,
|
||||
factor: MovementSpeedFactor,
|
||||
}
|
||||
|
||||
impl MovementBundle {
|
||||
@@ -93,6 +98,7 @@ impl MovementBundle {
|
||||
acceleration: MovementAcceleration(acceleration),
|
||||
jump_impulse: JumpImpulse(jump_impulse),
|
||||
max_slope_angle: MaxSlopeAngle(max_slope_angle),
|
||||
factor: MovementSpeedFactor(1.),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,6 +179,7 @@ fn movement(
|
||||
controls: Res<Controls>,
|
||||
mut controllers: Query<(
|
||||
&MovementAcceleration,
|
||||
&MovementSpeedFactor,
|
||||
&JumpImpulse,
|
||||
&mut LinearVelocity,
|
||||
Has<Grounded>,
|
||||
@@ -194,7 +201,8 @@ fn movement(
|
||||
|
||||
direction = direction.normalize_or_zero();
|
||||
|
||||
for (movement_acceleration, jump_impulse, mut linear_velocity, is_grounded) in &mut controllers
|
||||
for (movement_acceleration, factor, jump_impulse, mut linear_velocity, is_grounded) in
|
||||
&mut controllers
|
||||
{
|
||||
let mut direction = direction.extend(0.0).xzy();
|
||||
|
||||
@@ -203,8 +211,8 @@ fn movement(
|
||||
(rig_transform.forward() * direction.z) + (rig_transform.right() * direction.x);
|
||||
}
|
||||
|
||||
linear_velocity.x = -direction.x * movement_acceleration.0 * delta_time;
|
||||
linear_velocity.z = -direction.z * movement_acceleration.0 * delta_time;
|
||||
linear_velocity.x = -direction.x * movement_acceleration.0 * delta_time * factor.0;
|
||||
linear_velocity.z = -direction.z * movement_acceleration.0 * delta_time * factor.0;
|
||||
|
||||
if is_grounded && jump_requested && !*jump_used {
|
||||
linear_velocity.y = jump_impulse.0;
|
||||
|
||||
Reference in New Issue
Block a user