From 136c6918c7d9f3ebe12c4535c438a2c67f01c110 Mon Sep 17 00:00:00 2001 From: freddie-a <57713959+freddie-a@users.noreply.github.com> Date: Sat, 29 Oct 2022 22:45:55 +0100 Subject: Add bullet collisions --- Bullet.gd | 7 ++++++- Bullet.tscn | 7 ++----- Enemy0.tscn | 2 +- KinematicBody2D.gd | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Bullet.gd b/Bullet.gd index b2058ba..9e64b08 100644 --- a/Bullet.gd +++ b/Bullet.gd @@ -13,7 +13,12 @@ func _physics_process(delta): velocity = global_position.direction_to(target) * speed shot = true velocity = move_and_slide(velocity) - + for i in get_slide_count(): + var collision = get_slide_collision(i) + if collision.collider: + collision.collider.free() + if velocity == Vector2(0.0, 0.0): + queue_free() diff --git a/Bullet.tscn b/Bullet.tscn index d2f4c14..f79445f 100644 --- a/Bullet.tscn +++ b/Bullet.tscn @@ -3,17 +3,14 @@ [ext_resource path="res://Bullet.gd" type="Script" id=1] [ext_resource path="res://icon.png" type="Texture" id=2] -[sub_resource type="CapsuleShape2D" id=1] -radius = 8.0 +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 31, 31 ) [node name="Bullet" type="KinematicBody2D"] -position = Vector2( 648, 360 ) script = ExtResource( 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] -position = Vector2( -1, 1 ) shape = SubResource( 1 ) -disabled = true [node name="Sprite" type="Sprite" parent="."] texture = ExtResource( 2 ) diff --git a/Enemy0.tscn b/Enemy0.tscn index 306afd6..225f15c 100644 --- a/Enemy0.tscn +++ b/Enemy0.tscn @@ -3,7 +3,7 @@ [ext_resource path="res://assets/Likkan-boss.png" type="Texture" id=1] [ext_resource path="res://Enemy0.gd" type="Script" id=2] -[node name="KinematicBody2D" type="KinematicBody2D"] +[node name="Enemy" type="KinematicBody2D"] script = ExtResource( 2 ) [node name="Sprite" type="Sprite" parent="."] diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd index 4f2949c..96484f3 100644 --- a/KinematicBody2D.gd +++ b/KinematicBody2D.gd @@ -34,5 +34,5 @@ func _physics_process(delta): get_owner().add_child(obj) var bodies = get_overlapping_bodies() for body in bodies: - if body.get_name() != "Bullet": + if not "Bullet" in body.get_name(): emit_signal("hit", delta) -- cgit v1.2.3-70-g09d2