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:
"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
}
]
}All random values apply to the enemy when it's spawned at the level!
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:
Edit levels files and create enemy based on similar enemies structures
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.
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:

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:

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

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