目前我使用两个物体(彗星和船)的位置来检测它们是否碰撞。
fn collision_detection(
comets: Query<&Transform, With<Comet>>,
mut ships: Query<(&Transform, &mut ShipStatus), With<Ship>>,
) {
for comet in comets.iter() {
for (ship, mut status) in ships.iter_mut() {
if comet.translation.x < ship.translation.x + 80.0 && comet.translation.y < ship.translation.y + 80.0
&& comet.translation.x > ship.translation.x - 80.0 && comet.translation.y > ship.translation.y - 80.0 {
status.dead = true;
}
}
}
}
但是必须有更好的方法来做到这一点。