Game Dev in Progress… Day 16

Photo by Ilya Pavlov on Unsplash

Hello and happy Wednesdays!!! This weeks has gone pretty fast and it’s already half way through the week. Progress has been slow going but I’m almost done with the 2D Course Phase II: Core Programming. The feature that I implemented and thankfully finished is the Homing Projectile Powerup. This feature would take the form of a power up that enables the Player to fire homing missiles (in my case, homing lasers.) I had few problems when I tried my hand in implementing this feature.

The first problem that I had to solve was to figure out how find the target that I’m looking for. My logic for this is that when I shoot my lasers, it should identify the closest target and go towards it. If they are not targets, then just act like a normal laser, if they are multiple targets, choose the closest one. I had a hard time trying to figure out how to implement this but fortunately Google was there to help. I quickly figure it out by using the method GameObject.FindGameObjectWithTags. After a quick look in the API, I found a code example that was the exact thing I was looking for. I used it and modified a bit to work for my program.

The second problem that I had to deal with was to make my laser go towards the target. This was an easy problem to solve because I already have code that I used in an earlier feature that I was able to modify and use for this. However, I was having a problem where the lasers stayed at the targets spot long before it was destroyed if I fired multiple lasers. This is because of how I handled destroying the game object. In order to play the destruction animation, I delayed the destruction of the object so the animation won’t get interrupted. So in order to fix this, I instead created an if statement that checked if the game objects collider (which I destroyed for another reason) was still active. If not it would the laser would keep moving forward and act as if the enemy was destroyed.

I am 90% of the way done with the 2D course. Hopefully tomorrow I can finish it but the hardest challenge is coming up. This challenge is to implement a Boss AI that will appear on the last wave. Thank you all for reading.


Cristian Aspacio