Gamasutra: The Art & Business of Making Gamesspacer
View All     RSS
October 20, 2014
arrowPress Releases
October 20, 2014
PR Newswire
View All
View All     Submit Event





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


 
Stirring Up a Storm in Unity's Shuriken
by Alex Rose on 07/30/12 07:29: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.

 

Unity's new particle system, Shuriken is a pretty versatile tool, and it's really useful for making animations look slick.

It does have its flaws, though, as I discovered whilst attempting to make a particle tornado. Its main downfall is that it lacks a polar coordinate system and, much as polar coordinates are the bane of my student life, I have to admit they're pretty damned useful when you're trying to make a tornado.

I looked around the interwebs and couldn't find any solutions to my problem that didn't involve paying for content, so I put on my maths hat and started deriving.

Now, there are a whole bunch of spirals, but the most obvious (and, thankfully, simplest) one is the Archimedean spiral, whose "arms" are equally spaced, and it follows the basic polar formula:

r=a+btheta

Now, that's all well and good in polar coordinates, but we need to know it in cartesian. Not only that, but we also have to differentiate it, since Shuriken wants particle lifetime velocities, not displacements.

So x=rcos(theta) and y=rsin(theta) .

We want to differentiate that with respect to time, but we don't have a time term. Luckily, we know that it's rotating at a constant rate, so the angle is going to increase at a constant rate, so we can just define:

theta = lambda t.

Our tornado is going to increase in height at a constant rate too, so our z component of velocity is just going to be some constant that we can choose later in Shuriken. Meanwhile, our x and y components of velocity can be derived from our known formulae for x and y:

x = (a+blambda t)cos(lambda t)

v_x = (blambda )cos(lambda t)-(a+blambda t)sin(lambda t)

And

y = (a+blambda t)sin(lambda t)

v_y = (blambda )sin(lambda t)+(a+blambda t)cos(lambda t)

It's all very well and good deriving that, but my feeble human brain can't interpret a harmonic equation as something useful, and I'm sure even those more gifted of us would miss the more subtle behaviours of this equation (specific peaks, turning points etc.)

So I gave my brain a rest, arbitarily chose a, b and k, and threw it into MATLAB with 400 data points.

That led me to this graph:

Image

Which I then meticulously plotted in Shuriken. It has a limited number of nodes, and you have to change the angles for each point so it forms a smooth curve. In short: It's disgusting to do, and it ends up with something like this:

Image

This is an absolute pain to plot. You have a limited number of nodes you can use, and you have tweak each one so that it ends up sinusoidal. However, if you'd rather spend 5 minutes plotting some points than paying $25 for a tornado from the asset store, this is probably your best bet.

This will form an "ideal" tornado, which doesn't twist around randomly. For things like whirlpools and black holes, this works just great (if you have good textures and tweak the values properly), or in the case that you WANT an ideal tornado because it fits with your graphical style. However, if you're looking for it to be more realistic, it's pretty achieveable, but you'll have to do a lot of messing around in the Force tab. Just set it to give a random curve between two constraining curves in x and y, and you'll get your randomised moving tornado. It'll also work pretty well if you set it to simulate in world space rather than local space, and have the particle system itself move around, in which case you'll probably want a second particle system at the base making some basic dust effects.

It's fun to note that if Unity added a polar coordinate system to Shuriken, the graph above would consist of 2 identical horizontal lines. Just slightly easier.

Here's how it looks in the end (using Unity's standard smoke texture, with it tweaked to different settings):

Obviously you can then tweak it however you see fit, and most importantly, texture it properly, but for now you can see the definite spiral shape.

Enjoy.

(Originally posted with LaTeX formulae at: http://www.vorpal-games.com/blog/)


Related Jobs

Nuclear Division
Nuclear Division — Sherman Oaks, California, United States
[10.20.14]

Senior Game Designer
Rumble Entertainment, Inc.
Rumble Entertainment, Inc. — San Mateo, California, United States
[10.20.14]

Lead Designer/Creative Director
Nintendo of America Inc.
Nintendo of America Inc. — Redmond, Washington, United States
[10.20.14]

Visual Development Artist
Filament Games LLC
Filament Games LLC — Madison, Wisconsin, United States
[10.20.14]

Web & Interaction Designer






Comments


Ian Morrison
profile image
Ouch! Surely there has to be a way to generate those curves automatically within Unity using a script or wizard... attempting to tweak a, b and lambda otherwise would be fairly tedious.

Still, the results speak for themselves... that's a pretty neat looking particle emitter! Thanks for sharing your process!

Alex Rose
profile image
Thanks!

Tweaking a and b are pretty simple, actually. The former simply controls the initial direction of the tornado, so you can just change the rotation yourself, but I wanted to be thorough. The latter can be tweaked by changing the magnitude of the graph on the left (e.g. mine is set to 4 on there).

But, indeed, changing lambda is a massive hassle and involves replotting the points again with a shorter time period, so you get more full rotations. It may be possible to use a script to modify the velocity over lifetime, but I couldn't find any way to modify that within the class.

http://docs.unity3d.com/Documentation/ScriptReference/ParticleSys
tem.html

Seems like you can only change initial values.

Either way, once it's actually made, 8 full rotations or so will probably do the trick in most cases, and then you can just adjust particle size, texture and the magnitudes of the velocity to tweak it more to your liking.

Emil Johansen
profile image
It should indeed be possible to generate the curves in a small editor script, abstracting the problem and reducing iteration time significantly.

Jeremy Alessi
profile image
Or you could just attach the particle emitter to a spinning transform ... show of hands?

Still, this is a very cool if over thought way to use Shuriken. Thanks for sharing!

Alex Rose
profile image
Yep, that works too, though I find you end up with more of a spinning cone shape if you use local space, and it doesn't work at all in world space. You don't get the layered effect like this; all the particles spin in unison. It works to an extent though, but you wouldn't be able to tell it's a tornado from a still screenshot.

Ian Morrison
profile image
Perhaps an alternative solution: Unity does allow you to access the particles during runtime. It should be viable to write a script that applies your velocity (or even position) functions to each particle during update, without going through Shuriken at all.

Alex Rose
profile image
True, but at that point you may as well code your own particle system from scratch.

I think the simplest solution would be for Unity themselves to just add a polar tab that can convert your points to cartesian. It'd probably be minimal effort on their part. I've seen people request it, and they've said they'll consider it.


none
 
Comment: