Skip to main content
‹ Back to Tutorials
Intermediate Unity

Learn how to make Games: Unity (Part 7) - Creating Bullets, Setting up keyboard input, and firing!

Oct 18, 2020
About this tutorial

Hi I'm Jerry from Bliz Studio LLC. Nothing is more satisfying than creating some bullets in your game and getting input from the player to fire those in your game. Here is the process to do that in Unity3D and Playmaker as the visual scripting tool. How to Make a Video Game With Unity3D and Playm

Written Guide

Part 7 of the space shooter series gives the rocket its weapon: a bullet drawn in Photoshop, fired with the space bar, trailing particles, cleaning itself up, and landing with sound and camera shake. Each piece is small, but together they're the loop you'll reuse for any projectile system.

Step 1 — Draw the bullet and auto-export it

In Photoshop, draw a bullet roughly the width of the ship's nose — blunt at the top, tapered at the back, yellow-orange with a darker interior and a subtle glow. The export trick: rename the layer bullet.png and enable File > Generate > Image Assets, and Photoshop writes the PNG to a folder automatically on every save. Drag it into Unity's Sprites folder and into the scene.

Step 2 — Particle trail

Right-click the bullet and add a particle system so it spawns as a child. Set start speed to 0 (the bullet's motion carries the trail) and — the key setting — simulation space to World instead of Local, so spawned particles stay where they were emitted and stretch into a trail behind the bullet. Color goes Random Between Two Colors (yellow to light orange), start size Random Between Two Constants at 0.2-0.3, rate over time around 100, and a short lifetime of about 0.05-0.2 seconds so the trail stays tight.

Step 3 — Velocity and self-destruction

Add an FSM named Move Bullet with Set Velocity on the Y axis. Playmaker prompts for a Rigidbody — accept it, but uncheck gravity, or the bullet arcs back down (the video demonstrates exactly that mistake). A speed of 9 ends up feeling right. For cleanup, drag the bullet's transform into the FSM and use Get Property to read local position Y every frame, then Float Compare it against a travel distance (10 at first, tightened to 6). At the threshold, a destroy bullet transition leads to a Destroy Self state. Important: leave Detach Children unchecked so the particle trail is destroyed along with the bullet — checking it leaves orphaned particle systems piling up in the scene. Finally, drag the finished bullet to the Prefabs folder and delete the scene copy.

Step 4 — Fire on space bar

On the rocket's existing FSM (which already reads movement axes), add Get Key Down listening for Space, sending a fire bullet event to a Create Bullet state. There, Create Object spawns the bullet prefab using the rocket as its spawn point. Don't forget the FINISHED transition looping back to the listener — without it, the FSM fires once and stops, another live mistake the video walks through.

Step 5 — Sound and shake

Two sound options: record foley (mouth-made laser noises) in the free Audacity, then tweak with Change Speed, Change Pitch, and Reverb effects and export an MP3 — or use Bfxr, which generates retro effects from presets like Laser/Shoot at the press of a button. Drop the file into a Sound folder, then add Play Audio to the Create Bullet state. For game feel, add iTween Shake Position on the main camera. Two tuning lessons: set the audio action's finished event to None (otherwise the state exits when the clip ends and skips the shake), and keep the shake subtle — the final values are a 0.1 vector over 0.1 seconds, way down from the first attempt.

Unity tools by Bliz Studio
Built for our own games — now on the Asset Store

Multi Tag — unlimited hierarchical tags for any GameObject. Hierarchy Pro — style your whole hierarchy with rules. Made by a Unity dev, for Unity devs.

Explore our Unity assets →