![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Dragon11705 |
So I am making a 2d platformer game where the player shoots thorns that kill enemies on contact. I am preloading the thorn scene from the player script and having it make an instance of the thorn. The thorn then moves via its own script, but I have a problem. I need it to detect when a body in the group ‘Enemy’ (enemies) enters the area2d, but I don’t know how to connect the area2d’s on_body_entered signal to the player script since the only way I know to connect it is via the inspector signal list which is only available in the thorn scene. There is no thorn in the same scene as the player until an instance is created, so is there a way to connect a signal of an instance or node from another scene to the player script? Here is some more information:
Sample of Player code:
var Thorn = preload('res://Scenes/Thorn.tscn')
func _physics_process(delta):
if Input.is_action_just_pressed("Shoot") and !shooting:
var thorn = Thorn.instance()
get_parent().add_child(thorn)
thorn.position = $Position2D.global_position
shooting = true
$ShootTimer.start()
Sample of Thorn code:
signal Shot_Enemy
func _on_Thorn_body_entered(body):
if body.is_in_group('Enemy'):
emit_signal('Shot_Enemy')
What I need to do is somehow connect the ‘Shot_Enemy’ signal of Thorn to the player or enemy script.
Nevermind it took me a while but I found a solution. I just have a variable set to true in the thorn script when it hits an enemy, and then check if the variable is true from the player script.
Dragon11705 | 2020-01-25 19:24