← Yop2D

How to make a door that opens with a key?

Beginner guide · no code

Français · English · Español · Deutsch · Italiano · Português · Русский · 中文 · 日本語 · العربية

ℹ️ For Yop2D Next, the new 2D + 3D version of Yop2D (coming soon). Button and node names are those of Yop2D Next.

🔍 How do I…? All short recipes, with a search

A door that blocks the way and a key. Without the key, the door stays shut. With the key, it disappears when the hero touches it.

You need:

Step 1: the cle variable

  1. Left panel, Scene tab, GAME VARIABLES section: tap New variable. Name (no spaces): cle; Type: Whole number; Starting value: 0. Then Apply.

Step 2: the hero

  1. Put an object in the scene (an image or a Square) and name it heros.
  2. Select heros, tap ⚙ Object behavior in the Inspector and choose Top-down character.
  3. Tap Object → Interactive → Joystick.

Step 3: the key

  1. Put an object in the scene (an image or a Square) and name it cle_obj.
  2. In the Inspector, Tag (family of objects) line, type cle.

Step 4: the door

  1. Put an object in the scene (an image or a Square) and name it porte.
  2. In the Inspector, Tag (family of objects) line, type porte.
  3. Select porte, tap ⚙ Object behavior in the Inspector and choose Ground / wall.

Step 5: the nodes

  1. Open the Blueprint.
  2. If object touches Tag: Object heros, Tag (family of objects touched) cle → Destroy Object: Object The involved object (the touched object) → Modify Variable: Variable cle, Value 1
  3. If object touches Tag: Object heros, Tag (family of objects touched) porte → If a variable…: Variable cle, Comparison is at least, Value 1
  4. True output → Destroy Object (Object porte)

The nodes

If object touches Tagheros · cle
→
Destroy ObjectThe involved object (the touched object)
→
Modify Variablecle · 1
If object touches Tagheros · porte
→
If a variable…cle · is at least 1
True →
Destroy Objectporte

Try it

Tap Play. Touch the door: it doesn't open. Pick up the key, touch the door again: it disappears.

👉 For a door that opens instead of disappearing: replace Destroy Object with Change Image (an open-door image) and remove its behaviour.