AI Optimization

In my game, enemies are a very important part to give the players a challenge. As of before this DevLog entry, the AI worked the following:

  • AI can spot player when player is close enough and not behind object.
  • AI can move towards the player.
  • AI can shoot the player every second with a 50% chance to miss.

This made it so it required little skill and more luck to beat them. It didn't matter how well you played, you just had to be lucky the enemies would miss their shots and you could even exploit the system which made it too easy.

Because of this I decided to completely change my enemies. They were going to throw grenades at the player instead of shooting at them. This made it so players had a way to avoid being hit and it wouldn't have to rely on RNG.

When I tried implementing this, I noticed that the player is way too fast to implement this properly. The grenade would have to drop at the players feet, but by the time the grenade was there, the player would be long gone.

This is when I thought of enemies that shoot fireballs like wizards. This is what I have right now.

Every time the enemies use their throwing animation, this big fireball will spawn and fly towards the player. It explodes on impact, so the player has to be aware of his surroundings to avoid these fireballs.

The enemies also have their own spots now and they won't chase the player anymore. On the next page you will find some screenshots of how it works.

First, I created an animation event which triggers the ThrowObject method of an enemy. This instantiates the fireball and registers the current player position. It then adds force to the fireball towards that position.

When it touches an object, it explodes as seen it the third screenshot. It registers all objects within it's range by using Physics.OverlapSphere(). It looks at the objects to see if the player or an enemy was hit, and it will deal damage according to which is calculated by the damage calculator (see DevLog entry: "Damage Calculation" for more on this).

Maak een gratis website. Deze website werd gemaakt met Webnode. Maak jouw eigen website vandaag nog gratis! Begin