Implementing an enemy
|
What? The first week of the project one of my main tasks was to create an enemy that would behave and travel in different movement-patterns. The enemy also had to be able to fire projectiles towards the player in order to create a challenge. The functionality for the enemy is split over three different scripts, with each script giving the enemy certain properties. For movement there are three different patterns that the enemy can travel in. The first of the three I created is a basic pattern. For this one the enemy simply moves straight across the screen horizontally. The second one makes the enemy travel in a sine wave from the right to the left of the screen. The final option for movement is to have the enemy home in on the player and chase them down. The functionality for shooting so far is very basic, only firing projectiles straight on towards the left side of the screen. Two separate scripts is in control of how the projectiles for the enemies work, giving them the ability to deal damage and travel. A third and final script controls how the enemy is to react to colliding with different objects in the game. How? To move the player on the X-axis I reduce the position component of the gameobject’s transform. To allow for moving in a sine curve the code can also change the Y-position to equal the sin of a constantly increasing variable multiplied by the amplitude of the wave. The homing pattern rotates the gameobject so that the left side of the enemy faces the player, and then moves the object closer to the player’s position. The projectiles move in the direction they are shot, which is shot in the direction that the enemy is facing, and kill the player on impact. Collision is handled by a script, which handles what the enemy can get damaged by, such as types of projectiles. The collision component is also responsible for letting one of our projectile types know whether or not the player should absorb the power from the enemy or not. Why? Our game is to be a bullet hell, so we decided to have quite basic movement for our enemies, hence only having three quite simple patterns. I felt that the different shooting patterns, that play a big part in bullet hell games would be too much to implement in the first week of work, thus not yet implementing it. Both of the programmers of the group feel that modularity and the script being simple to set up in unity is important. Therefore our scripts are separated such that one script handles one resource. |
