How do I program my character to pick a key to use to unlock a door (Im new)

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

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

:bust_in_silhouette: Reply From: BraindeadBZH

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

cant find anything that helped. thats why im asking here

eatthatpear | 2019-08-04 17:44

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.

BraindeadBZH | 2019-08-04 17:55

:bust_in_silhouette: Reply From: johnygames

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 on_Area_body_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.

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

eatthatpear | 2019-08-04 18:33

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.

johnygames | 2019-08-04 18:38