Created
May 27, 2021 15:25
-
-
Save ciwolsey/d87f738feb5356dc1a5327a1a8787fbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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