0 votes

Hey, how's it going? I'm making like and hide and seek mini game and I need help!
I have an area2d node set up with two sprite as its children. One is a kid and the other is a scary monkey face and I used the hide() to keep both of them hidden. When the player enters the area2d I want to be able to randomly select which sprite shows up but im having trouble trying to figure it out.

in Engine by (14 points)

1 Answer

+1 vote

I think you can connect the body_enter signal to a function like this:

func player_entered_area(body):
    var kid = get_node("Kid")
    var scary = get_node("Scary")

    var show_kid = (randi() % 2 == 0)

    kid.visible = show_kid
    scary.visible = not show_kid
by (29,090 points)

i also tried connecting it to the area2d and the player script.

nothing happens with area2d or Lost Jungle, but when I connect it to player it give the error i mentioned

would the path be the same if i have it connected to player?

The signal is connected to player in this one since i wasn't getting any response from Lost Jungle

You must connect to the node on which you put the script receiving that signal. Depending on where that node is in the hierarchy, the path to get the kid or monkey will change (it is relative).
When you connect the signal, the function name in the dialog must match with the one in your script.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.