Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | potatobanana |
what advantages and disadvantages between send signal to world and add_child(instance), and get_parent().add_child (instance)?
exmple:
signal from player
func shoot():
if can_shoot == true:
can_shoot = false
$fire_rate.start()
var bullet_pos = $turrent/bullet_spawn_pos.global_position
var bullet_dir = Vector2.RIGHT.rotated($turrent.global_rotation)
emit_signal("shoot",bullet_type,bullet_pos,bullet_dir)
to world
func _on_tower_Ballista_shoot(bullet, pos, dir) -> void:
var bullet_instance = bullet.instance()
bullet_instance.bullet_spawn_position(pos,dir)
add_child(bullet_instance)
exmple:
instance child from player to world
func shoot():
if can_shoot == true:
can_shoot = false
$fire_rate.start()
var bullet_pos = $turrent/bullet_spawn_pos.global_position
var bullet_dir = Vector2.RIGHT.rotated($turrent.global_rotation)
var bullet_instance = bullet_type.instance()
bullet_instance.bullet_spawn_position(bullet_pos,bullet_dir)
get_parent().add_child(bullet_instance)