batrix/scripts/player/player_attack.gd

34 lines
750 B
GDScript

class_name PlayerAttack
extends Area3D
signal attacked
@export var _collision_debug_material: Material
var _debug_collision_shapes := DebugCollisionShapes.new()
func _ready() -> void:
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
Debugger.add_event("attacked")
attacked.connect(func() -> void: Debugger.event_emitted("attacked", []))
body_entered.connect(_on_body_entered)
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("attack"):
_attack()
func _attack() -> void:
attacked.emit()
func _hit_projectile(projectile: Projectile) -> void:
projectile.queue_free()
func _on_body_entered(node: Node3D) -> void:
if node is Projectile:
_hit_projectile(node as Projectile)