fixed flickering on projectile spawn. send origin

This commit is contained in:
Magnus von Wachenfeldt 2022-08-16 21:03:03 +02:00
parent 614092a8eb
commit 05ca78229f
Signed by: magnus
GPG Key ID: A469F7D71D09F795
3 changed files with 19 additions and 14 deletions

View File

@ -243,17 +243,22 @@ fn client_sync_players(
network_mapping.0.remove(&server_entity);
}
}
ServerMessages::SpawnProjectile { entity } => {
let projectile_entity = commands.spawn_bundle(SpriteBundle {
sprite: Sprite {
color: Color::rgb(0.25, 0.25, 0.75),
custom_size: Some(Vec2::new(5., 5.0)),
ServerMessages::SpawnProjectile { entity, origin } => {
let projectile_entity = commands
.spawn_bundle(SpriteBundle {
sprite: Sprite {
color: Color::rgb(0.25, 0.25, 0.75),
custom_size: Some(Vec2::new(5., 5.0)),
..default()
},
..default()
},
..default()
});
})
.insert_bundle(TransformBundle::from(Transform::from_xyz(
origin.x, origin.y, 0.,
)))
.id();
network_mapping.0.insert(entity, projectile_entity.id());
network_mapping.0.insert(entity, projectile_entity);
}
ServerMessages::DespawnProjectile { entity } => {
if let Some(entity) = network_mapping.0.remove(&entity) {

View File

@ -63,8 +63,8 @@ fn main() {
app.insert_resource(new_renet_server());
app.insert_resource(RenetServerVisualizer::<200>::default());
app.add_system(server_update_system);
app.add_system(server_network_sync);
app.add_system_to_stage(CoreStage::Update, server_update_system);
app.add_system_to_stage(CoreStage::PreUpdate, server_network_sync);
app.add_system(move_players_system);
app.add_system(jump_system);
app.add_system(jump_reset);
@ -178,7 +178,7 @@ fn server_update_system(
);
let entity = spawn_projectile(&mut commands, origin, direction);
let message = ServerMessages::SpawnProjectile { entity };
let message = ServerMessages::SpawnProjectile { entity, origin };
let message = bincode::serialize(&message).unwrap();
server.broadcast_message(ServerChannel::ServerMessages.id(), message);
@ -339,7 +339,7 @@ fn spawn_floor(mut commands: Commands) {
},
..Default::default()
})
.insert_bundle(TransformBundle::from(Transform::from_xyz(0., 0., 0.)))
.insert_bundle(TransformBundle::from(Transform::from_xyz(-50., 0., 0.)))
.insert(RigidBody::Fixed)
.insert(Collider::cuboid(width / 2., height / 2.))
.insert(ActiveEvents::COLLISION_EVENTS);

View File

@ -57,7 +57,7 @@ pub enum ServerChannel {
pub enum ServerMessages {
PlayerCreate { entity: Entity, id: u64 },
PlayerRemove { id: u64 },
SpawnProjectile { entity: Entity },
SpawnProjectile { entity: Entity, origin: Vec2 },
DespawnProjectile { entity: Entity },
}