Day 10 — PHASE 2
Today I worked on a DEBUFF drop. I had some fun with this one and used the GameDev Monkey logo as the debuff. When the monkey hits the player, the player blinks red for 5 seconds, has his speed cut in half, Thrusters disabled and also he can’t fire his lasers; the out of ammo sound will play to indicate this as well. Overall I am pretty happy with my implementation. I spent some time animating the little monkey and even added a monkey sound as the players collects the debuff instead of the usual powerup sound. Check out the youtube video below the GIF if you want to hear the sound. For the blinking routine I used the same code we learned for the Game Over text.
Next I worked on 2 more enemy movements. I used a Switch statement in Void Update and created a Random ID number at Void Start that runs once so that as soon as the enemy spawns it is assigned a movement pattern for its life span. Eventually I can see myself adding random movement patterns on higher tier enemies to make them less predictable. For now I added enemies that come down diagonally both directions and also an enemy that zig zags. I really learned a lot about transform movement during this implementation and I can tell that I barely scratched the surface of what is truly possible with the right knowledge.
Once again I had to dig up some old math terms and do some research online to make this happen. Basically the enemy movement for the Zig Zag uses simple trigonometry. For my purposes I used Vector3.down to move the enemy downwards and then used the Mathf.Cos formula to oscillate around the X-AXIS. Also had to define the frequency of the oscillation and the magnitude of the wave( how wide it is). It came out pretty good and certainly makes the enemies more challenging now. In the process I came up with two weird bugs related to this particular enemy movement.
The first bug happened when the enemy went off screen and respawned up above. He would get stuck and oscillate back and forth very quickly along the X axis at the same y coordinate. If you recall we programmed in enemy recycling when enemies went off screen and somehow the cosine function was affecting the random respawn location of the enemy. I fixed this by resetting the enemy position variable by making it equal to Transform.position and put this line of code after the random Vector3 respawn code for its transform.position.
The next bug occurred after I killed the enemy; his animation would continue to oscillate along the same trajectory. Again another head scratcher because in my death routine for enemies I had speed=0 and all my formulas for movement use that variable. I believe that both issues stem from the fact that the routines are in Void Update. What I decided to do is add a global Boolean statement called _canMove and enclosed all the movement script in Void Update in an if statement to check if it was true or false and then set it to false when the enemy died. Voila, problem solved. I then removed the speed = 0 code since that was redundant.
I am at a point though were I might take a break from Phase 2 for a few days and really focus on learning C#. While I feel pretty good about everything that I have learned so far and I am retaining most of it, I do feel the gaps in my knowledge and it is holding me back. My mind is creative and I trust myself with coming up with creative ways to implement the features I want, It takes me a lot longer than It should though. Sometimes I feel like I am reaching too high and then struggling because I am still not grasping basic things. Thats when I step back, take a simpler approach to get something functional and then build on that. Tomorrow I will put some more time in Phase 2 but then over the weekend its going to be all about the C# survival guide and doing lots of exercises to master the basics. At some point I want to also take some time to review all my code and try to clean up as much as possible to make it more efficient and easier to read.
Mahalo!