For the combat I gave myself a bit of a head start as I implemented attacks into my player avatar right at the beginning of the project which saved me a fair bit of time here. The feature here is to have the player who can damage an enemy which can split on contact kind of like a slime.
As the animations were mapped to buttons already the first thing I needed to do was add some colliders to the player's hands and feet so that when they collide with the enemy they can deal damage to the enemy.
After this, I needed to create the enemy and 2 smaller versions of it which can be children of this. after creating the enemy which is just a cube I need to create a script where I need to give the enemy some health as well as this I needed to create a game object inside for the smaller enemy that spawns after.
I set the code up so that the enemy will chase the player. Next, I needed to set up the collision with the player so, using the OnTriggerEnter function I set it up so that when the player's hands or feet collided with the enemy and when an attack is being triggered to deal damage to the enemy.
Then after the enemy's health is equal to zero it will span 2 smaller versions of itself for the player to destroy. As the smaller enemies have the same script as the enemy, I can have them split again as long as I give it a gameobject to split out of it.
Now all is left is to add in an attack for the enemy. for this, I decided to have them fire projectiles at the player when they are a certain distance. To do this I needed to set up a projectile and give it a script in which I give it a velocity etc.... I then in the enemy script add in some code in which to fire the projectiles at the player.
I also had to add a ridgidbody component to the enemies because without that they would be floating in the air which is a bit troublesome.
For my combat feature everything works just fine mostly there is an issue where when attacking if another body part i.e. left arm hits the enemy while they are kicking the enemy will still take damage, there is also the fact that to attack the player needs to hold down the button which is inconvenient at points as the attack is canceled if you let go too early.
As for polish, this feature could maybe do with some health bars and the smoother attacking, so the player doesn't need to hold buttons down. The additions of combos could also be a fun implementation to consider. multiple enemy types could also be a good addition.
Update: decided it was better to have the enemy chase the player only when they are a certain distance away so I changed the code so that when the movement uses the same distance value as when the enemy starts firing at the player.
Comments