Welcome to 2D Game Dev Journey - Day 1: Making Projectiles. Today marks the start of my journey to make a 2D game in Unity. In today’s article, I will go over how I made some laser effects that get spawned and shot from the player’s current position.
**When it comes to these posts where I am providing progress updates on my projects, I will not go too into how I make things work, so if you would like a more in-depth tutorial about anything I go over, just let me know in the comments.
Starting Point & Setup
Today I will be starting right where I left off in my Basic 2D Player Movement tutorial. Check that out if you are interested and/or want to follow along.
Making the Projectile GameObejct
The above screenshot shows the 3D object I created to represent my projectile. As you can probably see, the projectile I created has a cylindrical shape with pointed ends. I created the model of my projectile really quickly in Blender, where I exported the .FBX file and imported that into Unity.
Once In Unity, I added the point light and material to the model I created in Blender for the final result I showed in the first image. I also added a capsule collider for when I implement collisions with other GameObjects.
Instantiation and Shooting
With my projectile prefab now created, I added some code to start shooting every frame I had the space bar held down. Now the above demonstration looks pretty good, but there are a few problems with it. For one, I don’t really have much control as to how fast the projectiles are being shot off at. To fix that, let’s add a cooldown for each time we fire a projectile. The implementation I created allows for a shot to be fired off every 0.2 seconds. Within this step, I also made sure to destroy my GameObject once off-screen, so I don’t end up having tons of GameObjects that are not relevant anymore, as well as giving my projectile a spawn offset slightly above the player. Here are the results:
Thanks for checking in and reading today’s article. Tomorrow, I will be creating my enemy prototype, so look out for that if interested. As always, comments and critiques are welcome. If I have made any mistakes, please let me know so I can correct them for future readers. If you would like a more in-depth tutorial about anything I went over today, let me know and I will take the time to write something up.