← Yop2D

Questions about enemies and fighting

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

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?

How do I kill an enemy by jumping on it?

  1. The hero has the Platform character behaviour. The enemy has the tag enemy (for example a Patrol (back and forth) enemy).
  2. 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.
  3. Then: Destroy Object (Object = The involved object (the touched object), the squashed enemy) → Impulse (jump) (Object hero, Force -12): the hero bounces.
  4. 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?

  1. 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.
  2. On Start → Repeat (every 2 seconds, number of times 0 = endless).
  3. “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.
  4. 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).
  5. 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?

How do I make an enemy that finds its way through a maze?

How do I make an enemy follow a path?

  1. Tap Object → Tools → Create a path. Give a Name of the path (for example road).
  2. 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.
  3. 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.
  4. 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).
  5. 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?

How do I make a boss with a health bar?

  1. The boss is called boss. The bar: Object → Interface (HUD) → Progress bar, named boss_bar, with Maximum value 20 and Starting value 20.
  2. On Start → Give health to the object (Object boss, Health points 20).
  3. If object touches Tag (Object boss, Tag bullet) → Destroy Object (the involved object: the bullet) → Deal damage (Object boss, Damage 1).
  4. “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.
  5. 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?

How do I make a fighting game (punches, hit zones)?

  1. The opponent has the tag enemy. On Start → Give health to the object (Object opponent, Health points 100).
  2. A Punch button (Button with text): On Object Click (Punch) → Play animation (the hero, its attack animation) → Hit zone (fighting) (Object hero).
  3. 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.
  4. “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.
  5. 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?

  1. The enemies' route: Object → Tools → Create a path, named road (see “follow a path” above).
  2. Two models outside the screen, Visible in the game unticked: enemy (tag enemy) and bullet (tag bullet).
  3. 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).
  4. 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”).
  5. 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.