pub trait InputApplicator {
// Required method
fn apply(
&self,
world: &mut PhysicsWorld,
player_id: u8,
body_index: usize,
input: &FrameInput,
dt: Fix128,
);
}Expand description
Trait for mapping player inputs to physics forces/impulses.
Implement this to define how your game’s inputs affect physics bodies.
ⓘ
struct MyInputApplicator;
impl InputApplicator for MyInputApplicator {
fn apply(&self, world: &mut PhysicsWorld, player_id: u8,
body_index: usize, input: &FrameInput, dt: Fix128) {
let body = &mut world.bodies[body_index];
// Apply movement as velocity
body.velocity.x = body.velocity.x + input.movement.x * dt;
body.velocity.z = body.velocity.z + input.movement.z * dt;
// Jump
if input.has_action(0x1) {
body.velocity.y = Fix128::from_int(5);
}
}
}Required Methods§
Sourcefn apply(
&self,
world: &mut PhysicsWorld,
player_id: u8,
body_index: usize,
input: &FrameInput,
dt: Fix128,
)
fn apply( &self, world: &mut PhysicsWorld, player_id: u8, body_index: usize, input: &FrameInput, dt: Fix128, )
Apply a player’s input to their controlled body.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".