Skip to content

Commit

Permalink
Apply SmoothDelta in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Oct 25, 2024
1 parent 5ed4eca commit f123016
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/context_layering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl InputContext for PlayerBox {
ctx.bind::<Move>()
.with_wasd()
.with_modifier(Normalize)
.with_modifier(ScaleByDelta)
.with_modifier(SmoothDelta::new(SmoothKind::Linear))
.with_modifier(Scalar::splat(DEFAULT_SPEED));
ctx.bind::<Rotate>().with(KeyCode::Space);
ctx.bind::<EnterWater>().with(KeyCode::Enter);
Expand Down
2 changes: 1 addition & 1 deletion examples/context_sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl InputContext for PlayerBox {
ctx.bind::<Move>()
.with_wasd()
.with_modifier(Normalize)
.with_modifier(ScaleByDelta)
.with_modifier(SmoothDelta::new(SmoothKind::Linear))
.with_modifier(Scalar::splat(DEFAULT_SPEED));

ctx.bind::<Rotate>().with(KeyCode::Space);
Expand Down
4 changes: 2 additions & 2 deletions examples/context_switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl InputContext for OnFoot {
.bind::<Move>()
.with_wasd()
.with_modifier(Normalize)
.with_modifier(ScaleByDelta)
.with_modifier(SmoothDelta::new(SmoothKind::Linear))
.with_modifier(Scalar::splat(DEFAULT_SPEED));
instance.bind::<Rotate>().with(KeyCode::Space);
instance.bind::<EnterCar>().with(KeyCode::Enter);
Expand Down Expand Up @@ -134,7 +134,7 @@ impl InputContext for InCar {
ctx.bind::<Move>()
.with_wasd()
.with_modifier(Normalize)
.with_modifier(ScaleByDelta)
.with_modifier(SmoothDelta::new(SmoothKind::Linear))
.with_modifier(Scalar::splat(DEFAULT_SPEED + 200.0)); // Make car faster.
ctx.bind::<ExitCar>().with(KeyCode::Enter);

Expand Down
2 changes: 1 addition & 1 deletion examples/local_multiplayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl InputContext for PlayerBox {
// In our case we cant to add modifiers for all players.
ctx.bind::<Move>()
.with_modifier(Normalize)
.with_modifier(ScaleByDelta)
.with_modifier(SmoothDelta::new(SmoothKind::Linear))
.with_modifier(Scalar::splat(DEFAULT_SPEED));

ctx
Expand Down
2 changes: 1 addition & 1 deletion examples/player_box/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl PlayerBoxPlugin {
}
}

pub(super) const DEFAULT_SPEED: f32 = 400.0;
pub(super) const DEFAULT_SPEED: f32 = 10.0;

#[derive(Bundle, Default)]
pub(super) struct PlayerBoxBundle {
Expand Down
2 changes: 1 addition & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl InputContext for PlayerBox {
.with_wasd()
.with_stick(GamepadStick::Left)
.with_modifier(Normalize) // Normilize to ensure consistent speed, otherwise diagonal movement will be faster.
.with_modifier(ScaleByDelta) // Multiply by delta to make movement independent of framerate.
.with_modifier(SmoothDelta::new(SmoothKind::Linear)) // // Make movement smooth and independent of the framerate. To only make it framerate-independent, use `ScaleByDelta`.
.with_modifier(Scalar::splat(DEFAULT_SPEED)); // Additionally multiply by a constant to achieve the desired speed.

ctx.bind::<Rotate>()
Expand Down
2 changes: 1 addition & 1 deletion examples/ui_priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl InputContext for PlayerBox {
ctx.bind::<Move>()
.with_wasd()
.with_modifier(Normalize)
.with_modifier(ScaleByDelta)
.with_modifier(SmoothDelta::new(SmoothKind::Linear))
.with_modifier(Scalar::splat(DEFAULT_SPEED));
ctx.bind::<Scale>()
.with(InputBind::new(Input::mouse_wheel()).with_modifier(SwizzleAxis::YXZ))
Expand Down
1 change: 1 addition & 0 deletions src/input_context/input_modifier/smooth_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct SmoothDelta {
/// Multiplier for delta time, determines the rate of smoothing.
///
/// By default set to 8.0, an ad-hoc value that usually produces nice results.
/// See also [`Self::with_speed`].
pub speed: f32,

prev_value: Vec3,
Expand Down

0 comments on commit f123016

Please sign in to comment.