Skip to main content

Module modifier

Module modifier 

Source
Expand description

Action values are stored in two forms:

During EnhancedInputSystems::Update, input is read for each Binding as an ActionValue, with the variant depending on the input source. This value is then converted into the ActionValue on the associated action entity. For example, key inputs are captured as bool, but if the action’s output type is Vec2, the value will be assigned to the X axis as 0.0 or 1.0. See Binding for details on how each source is captured, and ActionValue::convert for how values are transformed.

Then, during EnhancedInputSystems::Apply, the value from ActionValue is written into Action<C>.

Modifiers are added as components to either the binding or the action entity. If they are attached to the action entity, they affect all bindings of the action and are applied after all binding-level modifiers. Within a single level, modifiers are evaluated in their insertion order.

Applying bindings at the input level allows you to have different behaviors for different input sources. You may want to have a dead zone for analog sticks, but not for keyboard keys, or scale sensitivity differently for mouse and gamepad inputs.

Creating common modifier configurations can be repetitive. To simplify this, we’ve provided several preset modifiers that cover common use cases.

§Example

This example uses the preset modifiers to quickly create and bind a zoom action for a fly camera, and tweaks it further using both action and input-level modifiers.

use bevy::prelude::*;
use bevy_enhanced_input::prelude::*;

#[derive(Component)]
struct FlyCam;

#[derive(InputAction)]
#[action_output(f32)]
struct Zoom;

let mut world = World::new();
world.spawn((
    Camera3d::default(),
    FlyCam,
    actions!(FlyCam[
        (
            Action::<Zoom>::new(),
            // Apply scale at the action level for all bindings.
            Scale::splat(0.1),
            Bindings::spawn((
                // In Bevy, vertical scrolling maps to the Y axis,
                // so we apply `SwizzleAxis` to map it to our 1-dimensional action.
                Spawn((Binding::mouse_wheel(), SwizzleAxis::YXZ)),
                Bidirectional::new(GamepadButton::DPadUp, GamepadButton::DPadDown),
            )),
        ),
    ]),
));

Modules§

accumulate_by
clamp
dead_zone
delta_scale
exponential_curve
fns
linear_step
negate
scale
smooth_nudge
swizzle_axis

Traits§

InputModifier
Pre-processor that alter the raw input values.