make projectiles get destroyed when colliding with player

This commit is contained in:
2025-02-25 04:05:40 +10:00
parent 05f2a657f3
commit 2322d8ff62
5 changed files with 15 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
class_name Projectile
extends AnimatableBody3D
extends Area3D
const HEIGHT: float = 1
@@ -19,6 +19,7 @@ func _ready() -> void:
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
global_position = _start_position
global_position.y = HEIGHT
body_entered.connect(_on_body_entered)
func _physics_process(delta: float) -> void:
@@ -37,3 +38,10 @@ func init(velocity: Vector3, start_position: Vector3, lifetime: float = 10) -> v
func set_velocity(velocity: Vector3) -> void:
_velocity = velocity
func _on_body_entered(node: Node3D) -> void:
if node is not Player:
return
queue_free()