fix movement
This commit is contained in:
parent
7188b1466e
commit
46ebcdcafc
@ -120,7 +120,7 @@ fn server_update_system(
|
||||
.insert(Velocity::default())
|
||||
.insert(Player {
|
||||
id: *id,
|
||||
position: Vec2::new(10., 10.),
|
||||
transform: Transform::from_xyz(10., 10., 0.),
|
||||
})
|
||||
.id();
|
||||
|
||||
@ -165,7 +165,10 @@ fn server_update_system(
|
||||
|
||||
if let Some(player_entity) = lobby.players.get(&client_id) {
|
||||
if let Ok((_, player)) = players.get(*player_entity) {
|
||||
fired_at = player.position;
|
||||
fired_at = Vec2::new(
|
||||
player.transform.translation.x,
|
||||
player.transform.translation.y,
|
||||
);
|
||||
|
||||
let projectile_entity =
|
||||
spawn_projectile(&mut commands, fired_at, fired_at);
|
||||
@ -246,11 +249,15 @@ fn server_network_sync(
|
||||
|
||||
fn move_players_system(mut query: Query<(&mut Velocity, &PlayerInput)>) {
|
||||
for (mut velocity, input) in query.iter_mut() {
|
||||
let x = (input.right as i8 - input.left as i8) as f32;
|
||||
let y = (input.down as i8 - input.up as i8) as f32;
|
||||
let x_axis = -(input.left as i8) + input.right as i8;
|
||||
let y_axis = -(input.down as i8) + input.up as i8;
|
||||
|
||||
velocity.linvel.x = x * PLAYER_MOVE_SPEED;
|
||||
velocity.linvel.y = y * PLAYER_MOVE_SPEED;
|
||||
let mut move_delta = Vec2::new(x_axis as f32, y_axis as f32);
|
||||
if move_delta != Vec2::ZERO {
|
||||
move_delta /= move_delta.length();
|
||||
}
|
||||
|
||||
velocity.linvel = move_delta * PLAYER_MOVE_SPEED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ pub const PROTOCOL_ID: u64 = 7;
|
||||
#[derive(Debug, Component)]
|
||||
pub struct Player {
|
||||
pub id: u64,
|
||||
pub position: Vec2,
|
||||
pub transform: Transform,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, Component)]
|
||||
|
Loading…
Reference in New Issue
Block a user