-
I'm making a 2d game demo. The player is spawned like this, the children has a larger sensor collider for detect things in attack range: commands
.spawn((
RigidBody::KinematicPositionBased,
Collider::ball(TILE_SIZE.x / 2. * 0.8),
KinematicCharacterController::default(),
))
.insert(OnThisLevel)
.insert(sprite_assets.player())
.insert(player::Player::default())
.insert(global_rng.fork_rng())
.insert(Name::new("Player"))
.with_children(|partent| {
partent.spawn((
RigidBody::KinematicPositionBased,
Collider::ball(TILE_SIZE.x / 2. * 1.2),
Sensor,
TransformBundle::default(),
player::PlayerAttackRange,
Name::new("Player Attack Range"),
));
}); Other breakable items are spawned using /// Bundle for interactive sprite.
#[derive(Bundle, Clone)]
pub struct InteractiveSpriteBundle<T: Bundle> {
pub rigid_body: RigidBody,
pub collider: Collider,
pub sprite: T,
}
impl<T: Default + Bundle> Default for InteractiveSpriteBundle<T> {
fn default() -> Self {
Self {
rigid_body: RigidBody::Fixed,
collider: Collider::cuboid(TILE_SIZE.x / 2., TILE_SIZE.y / 2.),
sprite: T::default(),
}
}
} I query the attack using following system: fn player_attack(
input: Res<ButtonInput<KeyCode>>,
rapier_context: Res<RapierContext>,
mut query: Query<&mut AnimationSpriteState, With<Player>>,
mut query_attack: Query<Entity, With<PlayerAttackRange>>,
) {
let mut state = query.single_mut();
let attack_range = query_attack.single();
if input.pressed(KeyCode::Space) {
if state.deref() != &AnimationSpriteState::Attacking {
*state = AnimationSpriteState::Attacking;
for (c1, c2, intersecting) in rapier_context.intersection_pairs_with(attack_range) {
info!("Intersecting: {:?} {:?} {:?}", c1, c2, intersecting);
}
}
}
} But the log outputs nothing has intersecting = true:
How can i proper detect other entity with |
Beta Was this translation helpful? Give feedback.
Answered by
lightsing
May 18, 2024
Replies: 1 comment
-
resolved: need to proper set |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lightsing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
resolved: need to proper set
ActiveCollisionTypes
andActiveEvents
, otherwise theintersection_pairs_with
won't work