0 votes

This is my first video game and i would like to know how to do this. :) thank you

in Engine by (17 points)

2 Answers

0 votes
Best answer

Here's an idea to get you started:

The main concept is to create and Area node which will act as a trigger-zone. By entering the trigger-zone, the key will be picked. Later, when approaching the door, which will have its own Area node, the door will open providing that the key was previously picked.

I do not know what type of game you are making (2D/3D), but it should generally work the same.

1) Supposing you have a 3D game, you can create an Area node. Select the Area node and add a new script

2) you will notice that on the right side of the editor (Godot 3.1 default settings) there are two tabs: Inspector and Node.

3) Go to Node and double click the onAreabody_entered() signal. Connect it to the newly added script

4) Now your script has this signal attached to it. Here's where you put your logic. Create a new variable in the beginning of the script. Name it key_acquired or something informative.

5) Now the idea is that when you enter the Area of the key, the key_acquired variable should be set to true.

6) Similarly, whenever you enter the door Area, and providing you have acquired the key (thus setting the key_acquired varibale to true), the door should open.

Is that what you're aiming for? Upvote this answer if it is.

by (1,892 points)
selected by

Thank you im trying to make it in 2d. i wasnt specific

Then you should use and Area2D with the same signal. If it's the right answer, please mark it as such. If there is anything else you are having trouble with, either post a new question or ask it here, if it is relevant with this issue.

0 votes

I'm pretty sure you can find a tutorial on that on Youtube, on channel like GDQuest or Game From Scratch.

by (1,049 points)

cant find anything that helped. thats why im asking here

Well, in general questions like "how do I do program X in my game" are difficult to answer on a forum, so it is better to be more specific. So for example in your case it would be best to ask "Which node can I use to detect if the player is on the key or at the door?", in this case it would be quick to answer you to look at Area2D.

Please, remember that the forum is not here to write your game at your place, this is more the domain of tutorials or premade assets.

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.