shoot. TODO: fix collision and brief spawning at 0,0

This commit is contained in:
Magnus von Wachenfeldt 2022-08-16 20:46:10 +02:00
parent 56fdaabb1a
commit 614092a8eb
Signed by: magnus
GPG Key ID: A469F7D71D09F795
3 changed files with 17 additions and 15 deletions

View File

@ -275,12 +275,12 @@ fn client_sync_players(
for i in 0..frame.entities.entities.len() {
if let Some(entity) = network_mapping.0.get(&frame.entities.entities[i]) {
let translation = frame.entities.translations[i].into();
let transform = Transform {
let transform_bundle = TransformBundle::from(Transform {
translation,
..Default::default()
};
});
commands.entity(*entity).insert(transform);
commands.entity(*entity).insert_bundle(transform_bundle);
}
}
}

View File

@ -84,7 +84,7 @@ fn main() {
#[allow(clippy::too_many_arguments)]
fn server_update_system(
mut server_events: EventReader<ServerEvent>,
pos_query: Query<(&Transform, &Player)>,
pos_query: Query<(&GlobalTransform, &Player)>,
mut commands: Commands,
mut lobby: ResMut<ServerLobby>,
mut server: ResMut<RenetServer>,
@ -119,6 +119,7 @@ fn server_update_system(
},
..Default::default()
})
.insert_bundle(TransformBundle::from(Transform::from_xyz(0., 0., 0.)))
.insert(RigidBody::Dynamic)
.insert(LockedAxes::ROTATION_LOCKED)
.insert(Collider::cuboid(5., 5.))
@ -169,7 +170,7 @@ fn server_update_system(
for (transform, player) in pos_query.iter() {
if player.id == client_id {
let origin =
Vec2::new(transform.translation.x, transform.translation.y);
Vec2::new(transform.translation().x, transform.translation().y);
info!(
"spawned attack on server at origin {} with direction {}",
@ -226,7 +227,7 @@ fn update_visualizer_system(
fn server_network_sync(
mut tick: ResMut<NetworkTick>,
mut server: ResMut<RenetServer>,
networked_entities: Query<(Entity, &Transform), Or<(With<Player>, With<Projectile>)>>,
networked_entities: Query<(Entity, &GlobalTransform), Or<(With<Player>, With<Projectile>)>>,
) {
let mut frame = NetworkFrame::default();
@ -235,7 +236,7 @@ fn server_network_sync(
frame
.entities
.translations
.push(transform.translation.into());
.push(transform.translation().into());
}
frame.tick = tick.0;
@ -269,7 +270,7 @@ fn jump_system(mut players: Query<(&mut Jumper, &mut Velocity, &PlayerInput)>) {
}
fn jump_reset(
mut query: Query<(Entity, &mut Jumper)>,
mut query: Query<(Entity, &mut Jumper), Without<Projectile>>,
mut collision_events: EventReader<CollisionEvent>,
) {
for collision_event in collision_events.iter() {
@ -338,6 +339,7 @@ fn spawn_floor(mut commands: Commands) {
},
..Default::default()
})
.insert_bundle(TransformBundle::from(Transform::from_xyz(0., 0., 0.)))
.insert(RigidBody::Fixed)
.insert(Collider::cuboid(width / 2., height / 2.))
.insert(ActiveEvents::COLLISION_EVENTS);

View File

@ -148,13 +148,13 @@ pub fn setup_level(mut _commands: Commands) {
pub fn spawn_projectile(commands: &mut Commands, origin: Vec2, direction: Vec2) -> Entity {
commands
.spawn()
.insert(Transform {
translation: Vec3::new(origin.x, origin.y, 0.),
..Default::default()
})
.insert(Collider::ball(0.1))
.insert(Velocity::linear(direction * 10.))
.insert(ActiveEvents::COLLISION_EVENTS)
.insert_bundle(TransformBundle::from(Transform::from_xyz(
origin.x, origin.y, 0.,
)))
//.insert(Collider::ball(0.1))
.insert(RigidBody::Dynamic)
.insert(Velocity::linear(direction))
//.insert(ActiveEvents::COLLISION_EVENTS)
.insert(Projectile {
duration: Timer::from_seconds(3.5, false),
direction,