From Photographer to Video Game Creator — Day 3
I had some serious momentum going into today and to make it even better the day was starting super smooth! I was able to figure out my first couple challenges rather quickly and with very few roadblocks. These challenges consisted of working with the enemy behavior and triggering collisions between the enemy, the lasers, and the player. This process was started by learning how to input a Debug function so that I was able to see which objects were colliding.
When running the game, an alert message would show me when my enemy was colliding with my laser or my player.
These collisions were possible because a rigid body component was added to the laser and enemy prefabs. I also wanted to make sure that when the laser hit the enemy, both the enemy AND the laser were destroyed. This was accomplished by using a trigger collision. This type of collision gives the illusion that you have collected an object or the object has been destroyed. The best example of this would be like collecting the floating power ups in a Mario Kart race. Once the driver passes through the power up, it disappears or is destroyed.
The other type of collision is known as a hard collision. An example of this would be throwing a ball off a wall and the ball bouncing back in a direction.
Next up was to give the enemies a random spawn point back to the top of the screen if they were not destroyed. After a little Google’ing, I was able to figure out how to create this effect and now I had multiple enemies that I could shoot! The concept was starting to come together!
Now I needed my enemies to keep spawning and add a random factor so that they weren’t just falling down side by side every time. This is where I fell off the wagon…
SCRIPT COMMUNICATION has entered the chat and it isn’t here to make friends.
Sometimes objects need to reference one another and pull information from other scripts. In this case the enemies needed to know when the player had been destroyed so they would stop spawning. This was achieved by adding an “IEnumerator” instead of a “Void”. This allows for the use of “yield return”. It’s still a little unclear at the moment, but from what I can understand it gives you the ability to create a loop that will run until the rules are no longer true. So in this case the enemies will continue to spawn until the player destroyed. The enemies were also given a 5 second delay for spawning.
Last step of the day was to give the player some lives and link it back to the enemy script so that it would know when the player had been destroyed.
Now it’s starting feeling like a game!
See ya tomorrow!
-Myles M.