How to make a prompt pop up and scene with distance using an input interaction

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

Hello there Geniuses!, I’m very new to Godot and its script, however i was able to decently do some functions and am currently in the process of making a game. I was able to make something of an animated popup whenever my player walks into a collision.(Its basically a floating exclamation point in a chatbubble). I was able to do this by hiding the animated sprite and using signal codes like this :

onready var animatedSprite = $AnimatedSprite

func _on_WBSPrompt_area_entered(area):
$AnimatedSprite.visible = true“default”)

func _on_WBSPrompt_area_exited(area):
$AnimatedSprite.visible = false

And it works perfectly.
Now I’m trying to make it so that when I press a key it will go to a new scene or instance a scene (like dialogue or a zoomed version of it). I tried using:

func _on_WBSPrompt_area_entered(area):
$AnimatedSprite.visible = true“default”)
if Input.is_action_pressed(Insert Key):
get_tree().change_scene(“Insert Scene”)

But it informs me of an error saying that i cant use the area entered function like that.
I’m confused, is there a specific node or script that uses layers, that can read both collision of my player and a key. and yes I’m using a kinematic2dplayer with a normal collision box and an Area2D box for the area entered function.
I heard of using a Raycast2D node but even with the documents on it I’m completely lost.
Is there any way of doing this or at least a node that can assist with this.
Thank you for hearing me out and I hope the answers can help anyone who was wondering about a similar problem.

:bust_in_silhouette: Reply From: Andrea

use the input(event) function to manage key strokes.

if you need the new scene to be linked to the collision, you can store the collision result in a boolean like

var collided=false

func on_WBSPrompt_area_entered(area):
 $AnimatedSprite.visible = true"default")

func _input(event):
 if event.is_action_pressed("whatever_key_you_want") and collided:
  get_tree().change_scene("Insert Scene")

Thank You so much it was really insightful and much appreciated. I found a way to work around it but this way seems much more efficient an professional. Again thank you so much.

KLDGZ | 2021-01-03 21:41