Shooting with Signals?
I have a basic 2d gun set up, so that whenever the player shoots and it's raycast is colliding the player emits a signal.
I also have a box set up, so that when the player emits the signal it gets damaged.
When any box gets damaged, every box in the scene would lose a life.
How do I make the code to target what it's hitting specifically?
Here's my code...
for the player:
func _input(event): if event.is_action_pressed("shoot") and gun_ray.is_colliding(): emit_signal("shot_fired", gun_ray.get_collision_point())
for the box:
func _on_Player_shot_fired(arg): emit_signal("box_1_damaged") print(lives) func _on_Box_box_1_damaged(): lives -= 1
and just because, here's code that spawns a particle effect on the point of impact (found on the root node):
extends Node2D var hit_effect = preload("res://Scenes/HitEffect.tscn") func _generate_hit_effect(hit_position: Vector2): var effect = hit_effect.instance() add_child(effect) get_node("HitEffect").position = hit_position func _on_Player_shot_fired(hit_position: Vector2): _generate_hit_effect(hit_position)
thanks so much in advance!