Devlog - Enemies and Interaction

Hello again! For this week's update in my project I implemented the ‘enemies’ or more appropriately NPC targets. Alongside this I implemented the NPC’s behaviour, their spawning mechanics, their ‘health’ and gave the player a damage component allowing for the NPCs to be ‘killed’.

Creation Process

Human NPC Behaviour 

In creating the Human NPCs that the player will target during gameplay, I have begun with simple red circles. I gave the NPC game object a circle collider 2d component as well as a rigidbody 2d component with the gravity scale set to 0. Next I implemented the NPCs behaviour script which was a combination of a roaming script and a fleeing script. The script detailed that the NPC would roam the map at a certain speed and would also flee at speed when the player was detected within a certain radius. When the player leaves the NPCs detection radius it will stop fleeing. Ideally this script would make the NPC detect the player then run away for an extended distance before then stopping, instead of stopping as soon as the player leaves the detection radius. 

NPC Spawning

After creating the NPCs and their movement I now needed to implement them into the gameplay. I made the NPC game object a prefab and created an empty game object for the enemy spawners. I then implemented a spawning script that outlined what game object would be created (in this case the NPC), how often this game object would be created, and the maximum number of specified game objects allowed to exist at once. On top of this the script will not allow more game objects to be spawned if the player is within a certain radius. This is done to prevent players from easily farming NPCs and in turn beating the game as I mentioned in a previous devlog. After the spawner had been configured I placed them around the map per the key point positioning I outlined in the previous devlog. 

NPC Health and Player Damage

Next I needed the player to be able to ‘kill’ the NPCs which will grant score and time when future features are implemented. I began this by creating a script for the NPCs that gave them an adjustable amount of health, and the ability to take damage which would lessen this health or kill them (delete the game object). Now the next step was to allow the player to inflict damage onto the NPCs in order to ‘kill’ them. Utilising the collider components on both the player and NPC game objects I implemented a script that would take away a specified amount of damage from the NPC when the player collided with it. This allowed for the player to chase down NPCs and run into them causing them to be deleted. This feature combined with specifications on the spawner meant that as soon as one NPC was ‘killed’ another would spawn in a different area of the map instantly, allowing for continuous gameplay. 

Testing and Issues

Due to the greater number of complex scripts, components, features and mechanics implemented in this week I did encounter some irritating issues. Firstly, the script I’ve used for NPC behaviour isn’t very good at navigating the game map. The NPCs often get stuck in corners and kind of bounce off walls when trying to move around. To fix this I tried to implement 2d pathfinding using Navigation AI and NavMesh but was ultimately unsuccessful, I believe this may have been due to my game map being made from a tile map but I am not entirely sure. I was stuck trying to fix this for some time but just couldn’t get it. For now the NPC movement will be subpar but operational and I hope to revisit it at a later stage. Secondly, during my test plays I found that sometimes an NPC will spawn way outside the game map and far from any spawner. I have no idea why this is and am not sure if there is a method of tracing back the thought process behind its creation. This bug is not game breaking but reduces the number of NPCs that the player is able to ‘kill’. A possible solution I intend to try is to create a game object that surrounds the map and is unable to be passed or collided with in hopes of preventing any unwanted spawns. In terms of issues encountered last week I was able to fix the projectiles and player sprite clipping through some areas of the game map (although I have now removed the weapon mechanic as I intend for it to be a powerup of sorts implemented at a later date). I had adjusted the tile size to better suit the player and feel I was trying to achieve but this had unfortunately not adjusted the collider of the tilemaps. This meant that the sprite was bigger than the collider and game objects were able to slip in the gaps. To fix this I readjusted the tile map and grid size back to normal to match the collider, then scaled down the player to fit the environment which was what I should've done in the first place as it is much simpler. 

*Enemy spawning outside of game map

Leave a comment

Log in with itch.io to leave a comment.