Skip to content

Instantly share code, notes, and snippets.

@ciwolsey
Created May 27, 2021 15:25
Show Gist options
  • Save ciwolsey/d87f738feb5356dc1a5327a1a8787fbd to your computer and use it in GitHub Desktop.
Save ciwolsey/d87f738feb5356dc1a5327a1a8787fbd to your computer and use it in GitHub Desktop.
pub fn ship_movement(
time: Res<Time>,
player_input: Res<PlayerInputRes>,
mut query: Query<(&Ship, &mut Physics, &mut RigidBodyHandleComponent), With<Player>>,
mut rigid_body_set: ResMut<RigidBodySet>,
) {
for (ship, mut physics, rigid_body_handle) in query.iter_mut() {
if let Some(rigid_body) = rigid_body_set.get_mut(rigid_body_handle.handle()) {
let delta = time.delta_seconds();
physics.velocity += player_input.input_vector * ship.thrust * delta;
physics.velocity = physics.velocity * physics.friction;
let mut pos = *rigid_body.position();
pos.translation.vector += physics.velocity;
rigid_body.set_next_kinematic_position(pos);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment