Spinning Enemy
|
This week I worked on adding more enemies to the game, as we previously only had a single one. I made 4 new enemies but the one I want to focus on for this blog post is an enemy that in the concept document was called ”Squirt.” Squirt is an enemy that circles around while spinning around shooting bubbles to the left and right. Here’s what he was depicted as in the concept document:
Spinning and shooting quickly creates waves of bullets that the player has to dodge. In order to balance this I needed to make another prefab in unity for the projectile, since the one we used for the other enemies is pretty fast moving, it would make it incredibly hard to dodge his projectiles if they were the same speed. Also, since he shoots bubbles, one would expect them to be slower than rocks shot from slingshots, which the normal enemy projectile is modeled from. The behaviour script for him is fairly straight forward. I created two empty game objects as children of squirt, one to the left and one to the right, which work as spawn points for the bubble projectiles. Every update, the script instantiates the projectile in both those spawn points, as well as moving and rotating squirt. Rotation is easily done using unity’s built in Transform.Rotate() function. The concept document describes squirt’s movement as circular, but we currently have him move in an ellipse (which is easily changed if we want to change it). The reason for that is that the screen is 16:9, not 1:1, so we stretched the circle out to an ellipse with width:height ratio 16:9. This movement is done by increasing a float angle every update and making his x position equal to (16/9) * cos(angle) (this is done using unity’s Mathf.Cos() function) and his y position to sin(angle). The only complication that arose was in squirt’s ”falling state.” We decided for every enemy to have a falling state, where it can’t take damage but also can’t deal damage. The state is used to warn the player of what enemies will appear soon. Most enemies fall towards a random target on the other side of the screen. After they reach that target they will begin their normal movement pattern and start shooting. For squirt, however, we thought this would look strange. He would ”fall” to a position, move towards a target position and then start circling. We felt the transition from moving in a straight line to moving in a circle would look clunky so we decided that while in the falling state it should move like normal in the falling state and just transition to shooting and being able to take damage. I needed to rewrite some code for the falling state script but in the end it worked out well.
|
