Godot Version
4.3
Question
Hi! Im trying to send out a gun fired signal which is autoloaded. The signal works perfectly fine without a collision check, but when i add the collision check back in, the signal stops working. There doesnt seem to be any correlation between the collision check and the signal emitter.
This is the faulty code:
extends Node2D
@onready var gun_raycast = $GunRaycast
@onready var sprite := $Sprite2D
var _smoothed_mouse_pos: Vector2
signal gun_fired
func _process(delta: float) -> void:
_smoothed_mouse_pos = lerp(_smoothed_mouse_pos, get_global_mouse_position(), 0.3)
look_at(_smoothed_mouse_pos)
if Input.is_action_just_pressed("left_click"):
if gun_raycast != null and gun_raycast.is_colliding(): #The collision check. When this is commented out, the signal starts working.
print("Testing!") #This works
emit_signal("gun_fired") #this doesnt
Signal receiving code:
extends CharacterBody2D
@onready var healthLabel := $HealthBar
@onready var health:= 2200
func _ready() -> void:
Gun.gun_fired.connect(enemy_shot)
func enemy_shot():
print("Hit!")