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