Skip to content

Commit

Permalink
Merge pull request #301 from AnthonyTornetta/300-shields-stopped-working
Browse files Browse the repository at this point in the history
300 shields stopped working
  • Loading branch information
AnthonyTornetta authored Aug 2, 2024
2 parents a6fbd9c + fe178db commit 1824eaf
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cosmos_core/src/structure/shields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ use bevy::{
query::Changed,
system::{Commands, Query},
},
prelude::Parent,
reflect::Reflect,
};
use bevy_rapier3d::geometry::{Collider, ColliderMassProperties, CollisionGroups, Group, Sensor};
use bevy_rapier3d::{
geometry::{Collider, ColliderMassProperties, Group, Sensor},
plugin::RapierContextEntityLink,
prelude::CollisionGroups,
};
use serde::{Deserialize, Serialize};

use crate::netty::sync::{sync_component, IdentifiableComponent, SyncableComponent};
Expand Down Expand Up @@ -63,8 +68,12 @@ impl SyncableComponent for Shield {
/// Things that should collide with shields should be put into this group
pub const SHIELD_COLLISION_GROUP: Group = Group::GROUP_3;

fn on_add_shield(q_added_shield: Query<(Entity, &Shield), Changed<Shield>>, mut commands: Commands) {
for (ent, shield) in q_added_shield.iter() {
fn on_add_shield(
q_rapier_entity_link: Query<&RapierContextEntityLink>,
q_added_shield: Query<(Entity, &Shield, &Parent), Changed<Shield>>,
mut commands: Commands,
) {
for (ent, shield, parent) in q_added_shield.iter() {
assert!(shield.radius > 0.0, "Shield radius cannot be <= 0.0!");

let mut ecmds = commands.entity(ent);
Expand All @@ -74,6 +83,9 @@ fn on_add_shield(q_added_shield: Query<(Entity, &Shield), Changed<Shield>>, mut
DespawnWithStructure,
Collider::ball(shield.radius),
CollisionGroups::new(SHIELD_COLLISION_GROUP, SHIELD_COLLISION_GROUP),
*q_rapier_entity_link
.get(parent.get())
.expect("Missing rapier entity link on shield's parent"),
ColliderMassProperties::Mass(0.0),
Sensor,
));
Expand All @@ -82,6 +94,9 @@ fn on_add_shield(q_added_shield: Query<(Entity, &Shield), Changed<Shield>>, mut
.insert((
DespawnWithStructure,
CollisionGroups::new(SHIELD_COLLISION_GROUP, SHIELD_COLLISION_GROUP),
*q_rapier_entity_link
.get(parent.get())
.expect("Missing rapier entity link on shield's parent"),
ColliderMassProperties::Mass(0.0),
Sensor,
))
Expand Down

0 comments on commit 1824eaf

Please sign in to comment.