Godot Version
4.2.1
Question
Hi forum! I’m creating an 2d vampire surviors like game, and I have problem creating fork / split effect.
This is a projectile (bullet) scene, which accepts a stats object(damage, speed, duration…) and target nearest enemy on ready. The components read stats from root and handle related behaviors. The ProjectileStatsManager handles behaviors such as pierce, fork, chain and returning.
The behaviors are connected to the hitbox signal area_entered(whenever hits an enemy). For fork effect i wrote:
func _on_area_entered(area):
if owner_node.stats.fork > 0:
owner_node.stats.fork -= 1
Callable(fork).call_deferred()
return
func fork():
var forked_node = owner_node.duplicate()
owner_node.add_sibling(forked_node)
owner_node.target_direction = owner_node.target_direction.rotated(PI/6)
forked_node.target_direction = forked_node.target_direction.rotated(-PI/6)
However, the forked_node seems to be linked to the owner_node, thus distrupting hit counting. For example, both forked and original should chain 1 time after forking, but as they are linked and sharing the same stats object, only one of them can chain after forking.
To make things worse, as stats.fork > 1, the forked projectile would collide with the hurtbox instantly on born, triggering everything again. To prevent this, i added a var to ProjectileStatsManager:
func _on_area_entered(area):
if owner_node.stats.fork > 0:
if area == forked_from:
print("same area forked from!")
return
forked_from = area
owner_node.stats.fork -= 1
Callable(fork).call_deferred()
return
But it seems that the inner value is lost when duplicating. The forked node has a null value of forked_from.
I can’t think of a valid method of creating a fork effect . can you guys help me? I would be much obliged!