Godot Version
4.6
Question
So, I’m very new to gdscript and I’ve been trying to make a global that can make hitboxes for me, but I cannot for the life of me able to figure out how to get the body_entered signal to work.
extends Node
signal create_hitbox()
func _ready() -> void:
Signals.create_hitbox.connect(_create_hitbox)
pass
func _create_hitbox(position : Vector2,scale : Vector2,damage : float,time : float):
var hitbox = CollisionShape2D.new()
var area = Area2D.new()
get_tree().current_scene.add_child(area)
area.add_child(hitbox)
hitbox.scale = scale
area.position = position
area.monitoring = true
if area.is_node_ready():
area.body_entered.connect(_on_touched)
pass
else:
print("failed")
pass
await get_tree().create_timer(time).timeout
area.queue_free()
pass
func _on_touched(body, damage):
print("test")
pass