Labels

Thursday 10 April 2014

Starting Enemy AI

Once the level mechanics had been finished the next bit of scripting that I had to do was to start some sort of AI system for our enemies. The system itself will be pretty basic as our enemies are only really designed to patrol specific areas or simple stand still. The only slightly complex aspect our our enemy scripts will be the code that manages when our enemies are bugged and what that changes about our enemies.

The standard enemy uses a character controller component as it was more suitable than a rigidbody. The standard enemies will constantly move forwards in any direction that they are pointed. If they hit something or come to a ledge they will turn around and begin walking in the opposite direction. This is done by checking the current velocity of the enemy as well as using a raycast to detect the edges of platforms. In order to "kill" the enemies in our game each one has a collision box attached to their head that detects a collision only when the player is jumping down onto them. Below is a screenshot of the standard enemy in the engine and the code that manages the direction of the standard enemy:



As well as our standard enemy that remains grounded at all times, we also have a flying enemy that acts in a similar way to our standard enemy. However instead of moving forwards along the X axis, the flying enemy moves up and down along the Y axis, sort of hovering up and down. Below is a snippet of code that shows how the movement of the flying enemy is achieved:



No comments:

Post a Comment