Tutorial: Scripting Course #2 – Let's Create an Enemy

In this course, you will learn the basic scripting methods in ACTION GAME MAKER.

In Part 2, we will create an enemy character.


Preparation Before Starting the Course

We will continue using the same project from Part 1.
Please open the project and get ready to begin.

STEP 1: Set Up the Basic Enemy (Zombie) Configuration

  1. We will use the Zombie from the template objects as our enemy.
    Open a new tab, select Game Object, and configure the settings as follows:
  • Name: Any name you like (we’ll use Sample_Zombie here).
  • Template: characters
  • Type: Enemy_Zombie
  • Group: Enemy

Once created, press Ctrl+S to save the scene.


  1. Set up the basic settings.
    Open the BaseSettings section and configure the following:
  • Enable Auto H Flip: ON

In visual scripts, the system assumes the object is facing right. However, this object was designed facing left, so horizontal flipping must be enabled.

  • Enable Object Condition: CLOSE TO CAMERA

The object will remain disabled outside the camera view.

  • HP / Max HP: 5

1 HP is too low, so let’s set it to 5.

  • Invincibility Duration: 0.2 seconds

This is the duration of invincibility after taking damage. 1 second is too long for fast-paced attacks, so we’ll set it to 0.2s.


  1. Normally, you would need to set up collision detection and animations manually, but this template object already includes all of that, so no additional basic configuration is necessary.

Explanation

About Invincibility Duration

The invincibility duration is very important.
If not set, the enemy will continuously take damage as long as the attack hitbox overlaps them, leading to instant defeat.
On the other hand, if it’s too long, rapid-fire attacks like machine guns might not deal consecutive damage.
Tweak this setting based on the needs of your project.

STEP 2: Create the Script for the Enemy (Zombie)


  1. Click the :scroll: + icon to create a new Visual Script.
  2. Rename the first state to Walk, and set the animation to the zombie’s walk animation: E_01_act_003.
    Also, set the Facing Direction to Left, since the default direction is right.

  1. For Walk’s Executable Action, add TemplateMove.
    Leave the template type as Horizontal, but disable Auto Flip so the zombie only turns around when hitting a wall, not based on time.

  1. Let’s test it in-game. Place sample_zombie.tscn as a child of ObjectRoot in the BaseLayer.
  2. Press F5 or click the :play_button: to test play.
    The zombie should walk left and disappear when hit by a bullet.If it doesn’t work, check the following:
  • Zombie moves in the wrong direction: Make sure “Enable Auto H Flip” is enabled in BaseSettings and the Walk state’s direction is set to Left.
  • Bullets don’t disappear when hitting the zombie: Check the bullet’s script to ensure collision detection is working correctly.
  • The zombie not dying after hits is expected, because we haven’t added the death state yet.

  1. Now let’s create the Damaged state.
    Create a new state near AnyState called Damaged.
    Set the animation to E_01_act_008 (damage animation).

  1. In the action settings, reduce horizontal movement speed to 10%.
    This makes the zombie slow down during the damage animation.

  1. Add three actions:
  2. Play Audio: Use Zombie2 as the sound effect.
  3. Wait: Insert a 0.2s wait to allow the animation to play.
  4. Transfer to Previous Action: Returns to the prior state.

  1. Connect AnyState → Damaged.
    AnyState allows transition from any state, and “Transfer to Previous Action” returns to the prior state—like a “Common Event” for RPG Maker users.

  1. Add two conditions to the link:
  2. Contact With Attack Area
    Configure it to react when hit from any direction by the Player.
  3. HP ≠ 0

  1. Test it. The zombie should groan and stagger when hit, and stop reacting after 5 hits.

If it doesn’t work:

  • No reaction to hits: Check that the HP condition is reversed and the animation is properly set.
  • Still reacts after 5 hits: Make sure the logic condition is AND.

  1. Now let’s make the Death state:

  1. Add three actions to Dead:
  2. Change Object Property
  • Type: Object Property
  • Target: Self
  • Node: AttackCollision (:warning: NOT AttackArea2D)
  • Property: disabled
  • Value: On
    → Disables the hitbox so players don’t take damage from a corpse.
  1. Wait: 0.85s to allow the animation to play.
  2. Remove Self
    → Deletes the zombie from the game.

  1. Link AnyState → Dead, and set the condition to HP = 0 (this time, do not reverse the condition).

  1. Test play again. The zombie should groan and stagger up to 5 times, and on the 5th hit, play the death animation and vanish.

If anything doesn’t work as expected, check the links, states, and conditions carefully.


Next tutorial (Part 3):