Gamasutra: The Art & Business of Making Gamesspacer
Shooting Particles in Unity (For Beginners)
Printer-Friendly VersionPrinter-Friendly Version
arrowPress Releases
April 23, 2014
PR Newswire
View All





If you enjoy reading this site, you might also want to check out these UBM TechWeb sites:


 
Shooting Particles in Unity (For Beginners)
by Tony Yotes on 12/23/13 12:03:00 pm   Featured Blogs

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.

 

 

     For shooter mode in TriGrid, bullet sprites just didn't cut it. They were boring crystal sprites that shattered on impact. I needed something with more flare. More Geometry Wars like. I started messing with Unity's particle systems and discovered how to make a little fire ball. One color change and explosion effect later I had the shooting effect I wanted. Here is how I got those "pew pew" thingies to work.

 

 

     I basically made a looping particle emitter in a cone shape using Unity's particle editor. I made it so the effect spawns up to 1000 dots that change from light blue to lavender as the die within one third of a second.

 

 

  

 

     I made the particle effect it's own object, attached physics to it, and made it a trigger so that it could collide with game objects. I attached a script I named scriptShot so I could control what happens when it impacts something. 

 

 

 

     If you wanted to replicate my effect, here are the settings to do it. Releasing 130 particles at a time with an initial extra burst of 50 every time the loop resets. I made them move at a speed of 100 to get the speeding effect I wanted.

 

 

     Stretching out the cone path that the particles were stuck inside was pretty simple. Unity has sliders you can adjust. To make the tail longer, all I'd have too do is increase the lifespan of each particle.

 

 

     This is the method I used to make the player shoot particles. This was called every time the "Pew" button was pressed. It checks to see if less than 4 shots are already in play before firing. I wanted to limit the amount of active shots to make things more challenging. The player could shoot once in each direction if necessary, but that's it. A skilled player could possibly last forever, but triangles tend to sneak up on you and catch your flank.

 

 

     This code changes the direction the player is facing. In Unity the transform.eulerAngles variable determines where an object is facing. I do this so I only have to tell the arrow to move forward when it's in motion. The player's direction determines which way the shot spawns and which way the shot moves.

 

 

     The shot only knows to go forward. At the moment of its creation it checks the direction of the player and aligns itself to match it.

 

 

     When it's in play, its just a matter of moving it by 4 pixels every frame in whatever direction it's facing. Based on the way the particles orient themselves, it moves by subtracting its Z-value on the coordinate plane.

 

 

     After that, it was just a matter of determining what happens when it touches stuff. I made it so enemies die on contact and walls trigger the particle effect within the particle effect that plays an explosion animation and deletes the original blast. After that I save the blast and the explosion as prefabs to be summoned whenever the player taps the "Pew" button. Suddenly, I have a Shooter mode in TriGrid.


Related Jobs

SOAR Inc.
SOAR Inc. — Mountain View, California, United States
[04.23.14]

Game Designer/Narrative Writer
Giant Sparrow
Giant Sparrow — Santa Monica, California, United States
[04.22.14]

Game Designer
Blizzard Entertainment
Blizzard Entertainment — Irvine, California, United States
[04.22.14]

Starcraft II - FX Artist
Blizzard Entertainment
Blizzard Entertainment — Irvine, California, United States
[04.22.14]

World of Warcraft - VFX Artist






Comments


haim ifrah
profile image
about the performance on mobile devices, how this compare to using trail shader on mobile?
i know that rail shader don't batch but doe's particales bullets can have good performance?
(and batch...)

Tony Yotes
profile image
I use a custom shader I found on Google called Somian. All the others produced off colors for the transparent PNGs I used. The performances fine on my phone with 512 MB RAM.


none
 
Comment: