Godot Version
4.2
explanation :
hello :3
im trying to make a tank game , and i want to manage projectile(bullet , … ) spawns via signals and a spawn_projectile() method in each level (level scenes are also in group called “levels”) .
here is spawn_projectile() function :
#note: collision_layers => 1 :environment , 2 :player , 3 :enemies
func spawn_projectile(spawn_position:Vector2,projectile_rotation:float,projectile_scene:PackedScene,collision_array : Array[bool] = [true,false,false]):
var new_projectile = projectile_scene.instantiate()
new_projectile.position = spawn_position
new_projectile.rotation = projectile_rotation
for i in range(collision_array.size()) :
new_projectile.set_collision_mask_value(i , collision_array[i])
add_child(new_projectile)
each scene must connect their projectile_shot() to level.spawn_projectile() , and they do it like this :
signal projectile_shot(position:Vector2,rotation:float,projectile:PackedScene,collisisn_mask:Array[bool])
var is_shooting = false
@onready var level = get_tree().get_first_node_in_group("levels")
func _ready():
if level != null :
projectile_shot.connect(level.spawn_projectile)
func shoot():
if is_shooting : return
is_shooting = true
$FireCooldown.start()
projectile_shot.emit($BulletSpawnPoint.global_position,global_rotation,bullet_scene,[true,true,false])
func _on_fire_cooldown_timeout():
is_shooting = false
problem : it just doesn’t work !
what is weird ?
it was working up until adding collision_mask array to signals and methods(it was based on default collision mask of projectile scenes before ) , is it impossible to pass array via signals ? or i implemented it the wrong way ?