Having the player interact with something when the right conditions are met

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Lothrinn

Hello Godot community !

I’m working on a game where the player has to collect “light fragments” in order to complete the level. Right now when the player has collected enough of them, the altar lits up when the player goes near it (see the image below).
However I would like for the player character to play the “level complete” animation after pressing a certain key on the keyboard while he is in the body area of the lit altar but can’t figure out how to do it with code as Input.get_action_strengh in the player script and the altar script doesn’t do anything. Could someone please help me with that ?

(My player character uses an animated sprite where all the animations are stored and I can’t figure out if it’s possible to get those animations from the altar script attached to the altar scene.)

Here's the image

:bust_in_silhouette: Reply From: EmanuelOzorio

I not sure that’s the best way, but you can try something like this:

  • In the player script create a signal
  • When input clicks the button emit that signal
  • Connect the area_entered signal of the altar with a function on the altar script
  • The area_entered has a argument that is the object that collide with, in this case will be the player, connect the the signal of player with a function on the altar.
  • Do whatever you want in this function.

In this case, when you press the key, the player will emit a signal and this signal will trigger the function in the altar.