Hey guys, I've been trying to create a hitbox and a hurtbox program.
My design logic is that every hitbox is a combination of one or more than one Area2D node. Also, the Area2D node can be freely added.
This is my Hitbox code:
extends Node
onready var hurtboxes: Array = []
#the message to send to hurtbox
var message: Dictionary = {}
func _ready() -> void:
add_to_group("hitbox")
#looping through all the Area2D(hitboxes) node it possesses
for node in self.get_children():
if node is Area2D:
var hb: Area2D = node
hurtboxes.append(hb)
hb.monitoring = true
#connecting body_entered signal
hb.connect("body_entered", self, "_on_hurtbox_entered")
func _process(delta: float) -> void:
pass
func _on_hurtbox_entered(body: Area2D) -> void:
#this function wasn't triggered as it should
if body.get_parent().is_in_group("hurtbox"):
body.connect("hit", self, "get_hit")
func get_hit(dict: Dictionary) -> void:
#hit logic
pass
and this is the Hurtbox code:
extends Node
onready var hurtboxes: Array = []
#storing the message from the hitbox
var recieved_message: Array = []
func _ready() -> void:
add_to_group("hurtbox")
#looping through all the Area2D(hurtboxes) node it possesses
for node in self.get_children():
if node is Area2D:
var hb: Area2D = node
hurtboxes.append(hb)
hb.monitoring = true
#connecting the hurtbox signal
hb.connect("body_entered", self, "_on_hitbox_entered")
func _process(delta: float) -> void:
pass
func _on_hitbox_entered(body: Area2D) -> void:
#getting hit
if body.get_parent().is_in_group("hitbox"):
body.connect("hit", self, "get_hit")
func get_hit(dict: Dictionary) -> void:
recieved_message.append(dict)
So if any of the hitbox's Area2D child node detects a hutbox's Area2D child node, it should trigger the onhitbox_entered() function. But the function was never triggered when I tested it.
Any help would be appreciated!!!