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