Collision Plugin

This commit is contained in:
2026-09-16 19:30:58 +02:00
parent 339d2ffd6e
commit 9f22e8fbd9
2 changed files with 11 additions and 1 deletions
+9 -1
View File
@@ -15,7 +15,6 @@ fn check_collision(
mut has_collided: Local<bool>,
) {
if *has_collided {
println!("Collision!!!!!!!");
return;
}
@@ -28,6 +27,7 @@ fn check_collision(
collider_transform.translation.truncate(),
collider_collider.size / 2.0,
) {
println!("Collision!!!!!!!");
player_sprite.color = Color::srgb(1.0, 0.0, 0.0);
*has_collided = true;
break;
@@ -41,3 +41,11 @@ fn overlap(a_center: Vec2, a_half: Vec2, b_center: Vec2, b_half: Vec2) -> bool {
let overlap_y = (a_center.y - b_center.y).abs() < (a_half.y + b_half.y);
overlap_x && overlap_y
}
pub struct CollisionPlugin;
impl Plugin for CollisionPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, check_collision);
}
}