Collision Plugin
This commit is contained in:
+9
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user