How to add new enemy

Tutorial will help you to undestand how to create new enemy profile and add it to the level

Files & folders needed:

assets/creatures/enemy.json

assets/levels/ (?)

assets/scripts/p_game.gd (?)

assets/textures/

This is basic JSON structure of the enemy profile:

enemy.json
"soldier": {
	"weapons": ["w_ak","w_groza"],
	"attack_sound": "rifle_sound.wav",
	"miss_sounds": ["whine_1","whine_2","whine_3","whine_4","whine_5"],
	"texture": ["psoldier"],
	"accuracy": 0.85,
	"damage": [5,8],
	"health": [20,35],
	"exp": [5,8],
	"attack_delay": [2,5],
	"money": [35,65],
	"loot": [
		{
			"item": "medkit",
			"chance": 0.15,
			"amount": 1
		},
		{
			"item": "antirad",
			"chance": 0.03,
			"amount": 1
		},
		{
			"item": "medkit_army",
			"chance": 0.13,
			"amount": 1
		},
		{
			"item": "ammo_ak",
			"chance": 0.18,
			"amount": 1
		}
	]
}

For example, let's use scientist texture from assets/textures/ for new enemy.

Create new profile at the end of the file.

So we have scientist enemy with some medkits and antirad items drop chance and ammo for LR rifle.

Now wee need somehow to test this profile, but how? There are two options:

  1. Edit levels files and create enemy based on similar enemies structures

  2. Spawn enemy with scripts, but need to be spawned an a eyezone for enemy too.

But let's looks like combat system works on that diagram:

When player spawn at the level, and you want to start combat, you need to place: enemies, covers, eyezones triggers.

Enemy will be attack if player is inside eyezone, if you left that eyezone with debug fly mode, enemies will stop attacking you. Also player can't interact with NPCs, Doors and Loot items while in combat mode (eyezone area).

Every enemy on the level must have their eyezone id where they will be attack player if he will be inside.

If two or more enemies has same eyezone id, then combat will be randomly selected what enemy will be attack and them wait attack delay from enemy.json file before start next attack. So attack queue is randomized.

Covers must cover enemies when they hide there. Every enemy must be setup with list of shoot animations based on their positions and cover size, for example on diagram, left AI can shoot with standing animation, sitting from left and right side of the cover.

This is perspective from old level editor:

Player spawn in eyezone, that will trigger enemies linked to this eyezone id to start attack, using their animations

To properly setup enemy on the level you need to understand what keys need to be edited at enemy object.

Easy way to test new enemy is spawn eyezone and enemy at the start of the game at intro level.

Go to assets/scripts/p_game.gd file and look for:

There find "intro" level id and type this code to spawn eyezone and enemy:

Check the new game:

New enemy attack us with some delay, but he look at 0,0,0 rotation, you can change it of course!

We can fix rotation problem with calculating direction vector to player position with this code:

Fixed rotation

But this type of "fix" is a little bit odd of course, you can set rotation as you want just in spawn parameters, because some covers need different rotations and it can be not always rotated to the player, like roof top enemies etc.

Last updated