ℹ️ 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
Short answers to questions about enemies, shooting and fighting in Yop2D Next. The names in bold are the ones you see on the screen.
👉 A word you don't understand? See The words of Yop2D.
How do I lose a life when an enemy touches the hero?
- Create a game variable lives (New variable button, starting value 3) and give the tag enemy to your enemies (Tag (family of objects) line in the Inspector).
- Nodes: If object touches Tag (Object hero, Tag enemy) → Add to Variable (lives, -1) → Blink (Object hero, Duration 1500).
- This event fires only once per contact: the hero loses one life, not all of them, even if he stays stuck to the enemy.
- In 3D, an enemy that chases the hero attacks by itself when it is close: use the When an enemy attacks event.
- The full recipe, with the lives text and the end of the game: How to have 3 lives?.
How do I kill an enemy by jumping on it?
- The hero has the Platform character behaviour. The enemy has the tag enemy (for example a Patrol (back and forth) enemy).
- If object touches Tag: Object hero, Tag enemy, Side touched = “The bottom of the object (standing on something)”. The event only fires when the bottom of the hero touches the enemy.
- Then: Destroy Object (Object = The involved object (the touched object), the squashed enemy) → Impulse (jump) (Object hero, Force -12): the hero bounces.
- To lose a life when the enemy touches you from the side: two more If object touches Tag, one on the left side, one on the right side. Not “Anywhere”: otherwise jumping on its head would also cost a life.
How do I make an enemy shoot by itself?
- The shot model: a small object named enemy_shot, with the tag enemy_shot. Put it outside the screen and untick Visible in the game: Yop2D makes a copy of it for each shot.
- On Start → Repeat (every 2 seconds, number of times 0 = endless).
- “Each time” output → Shoot an object: Object A enemy, Object B hero, Model name enemy_shot, Direction “Toward an object (chosen in Object B)”. The shot flies toward the hero.
- When the shot touches the hero: If object touches Tag (hero, enemy_shot) → Destroy Object (the involved object: the shot) → Add to Variable (lives, -1).
- Several enemies? In Shoot an object, choose Object A “# enemy”: every object with this tag shoots. More details: How to shoot a projectile?.
How do I make an enemy that runs away?
- On Start → Flee an object: Object A = the one that runs away (a chicken), Object B = the hero, Speed 3.
- It moves away from the hero by itself, endlessly, and stops against walls.
- So that it doesn't leave the screen: Clamp to screen. To stop it (it has been caught): Stop the object.
- The opposite, an enemy that runs after you: Chase an object (see An enemy that chases the hero).
How do I make an enemy that finds its way through a maze?
- On Start → Go to an object (path): Object A = the ghost, Object B = the hero. Once is enough: the path is worked out again when the hero moves.
- It finds the shortest path by itself, square by square, and goes around walls: Ground / wall objects and the Solid tiles of a tile scenery.
- The “Arrived” output fires when it touches the hero. Diagonals = yes: it also moves diagonally. To stop it: Stop the path.
- To go to a precise spot (not toward an object): Go to a point (path).
How do I make an enemy follow a path?
- Tap Object → Tools → Create a path. Give a Name of the path (for example road).
- With Place points, tap the scene point after point, from the start to the end. ▶ Watch it go shows the route. A point with several exits is a crossroads.
- In the Blueprint: On Start → Follow the path (Object = the enemy, path road, speed 150). It is placed at the start, then moves from point to point.
- The “Reached the end” output fires at the end of the path. To stop it earlier: Stop following the path. In 3D: Follow a path (3D).
- A simple back and forth is enough? See An enemy that walks back and forth.
How do I make a missile that follows its target?
- The model: a hidden object named missile, outside the screen, whose image faces right. Give it the tag missile.
- Launch a guided missile (curve): Object A = the one that shoots, Object B = the target, Model name missile. The missile starts straight, then turns little by little toward the target: a real curve.
- Small turn (2) = wide curve; big turn (8) = it turns sharply. At the end of its lifetime, if it hasn't hit anything, it explodes by itself.
- The missile does nothing when it touches: add If object touches Tag (the target, tag missile) → Destroy Object (the involved object) → lose a life.
How do I make a boss with a health bar?
- The boss is called boss. The bar: Object → Interface (HUD) → Progress bar, named boss_bar, with Maximum value 20 and Starting value 20.
- On Start → Give health to the object (Object boss, Health points 20).
- If object touches Tag (Object boss, Tag bullet) → Destroy Object (the involved object: the bullet) → Deal damage (Object boss, Damage 1).
- “Still alive” output → Set Progress (Object boss_bar, New progress
=boss.vie). “Out of health” output: the boss disappears → Go to scene to your victory screen. - In 3D it's shorter: in the boss's Inspector, Health part, set Health points (0 = none) and Above it (during the game) = Health bar. Then Remove health points and the When an object has no health left event.
How do I shoot toward the spot I touch on the screen?
- End of Click → Shoot an object: Object A hero, Model name bullet, Direction “Toward the finger (where the screen is touched)”.
- The bullet leaves the hero toward the last spot touched. A finger on a joystick doesn't count: you can move and aim at the same time.
- It works in 3D too: the shot flies flat, toward the spot touched on the ground.
- The bullet model, the speed, the other directions: How to shoot a projectile?.
How do I make a fighting game (punches, hit zones)?
- The opponent has the tag enemy. On Start → Give health to the object (Object opponent, Health points 100).
- A Punch button (Button with text): On Object Click (Punch) → Play animation (the hero, its attack animation) → Hit zone (fighting) (Object hero).
- Zone settings: Who gets hit enemy, Damage 0 (the next node takes the health away). Set “Show the zone in game” to Yes to see its size and adjust it. The zone appears in front of the hero, just for the time of the hit.
- “Hit” output → Deal damage (Object = the involved object, the opponent that was hit; Damage 10). “Still alive” → Hit stop and Play sound. “Out of health” → the knockout: Go to scene, for example.
- The opponent hits back? The same on it, started by a Repeat, with Who gets hit = the hero's tag (and health given to the hero).
How do I make a tower defense game?
- The enemies' route: Object → Tools → Create a path, named road (see “follow a path” above).
- Two models outside the screen, Visible in the game unticked: enemy (tag enemy) and bullet (tag bullet).
- The waves: On Start → Repeat (every 2 s) → Generate clone (Spawner) (Object A and Object B = enemy) → Follow the path (the involved object = the copy, road). “Reached the end” output → Add to Variable (lives, -1) → Destroy Object (the involved object).
- A tower: On Start → Repeat (every 1 s) → Choose a target (Object tower, tag enemy, the closest, range in pixels 300) → “Target found” → Shoot an object (Object A tower, Object B = the involved object, model bullet, direction “Toward an object”).
- The bullet hits: If object touches Tag (Object “# enemy”, Tag bullet) → Destroy Object (the involved object: the bullet) → Destroy Object (The event's object: the enemy).
👉 For enemies that appear by themselves, see Enemies that appear; for the hero's health bar, A health bar.