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