Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently using Mercury Particle Engine for the particle effects in my game, and I'm trying to create a sort of lightning whip - basically a lightning effect bound to a line that curves when the player moves. I know how to use the editor, and I have particle effects working in game. However, I'm completely lost as to where I should start for this specific particle effect.

Perhaps if I could find the code for it in a different particle engine, I could convert it, but I can't seem to find that either. What I did find was a lot of tutorials for creating the lines associated with lightning programmatically, which doesn't help in this case because I don't want it to be rigid. Perhaps it would be more like some sort of laser beam with crackling effects around it? I'm running into a wall as far as even beginning to implement this goes.

share|improve this question
Like this lightning whip? – Eric Apr 9 '12 at 7:42
Something like that, yes. It would be controlled by a space ship and not a person. – Fibericon Apr 9 '12 at 7:46
If you say controlled, will it be able to collide with other objects (as some sort of weapon) or is it purely a visual effect to simulate exhaust gases? – Eric Apr 9 '12 at 8:04
It would collide as a weapon. – Fibericon Apr 9 '12 at 8:05
This might be nice too: – Tili Apr 10 '12 at 8:09
up vote 3 down vote accepted

Despite lightning consisting out of free electrons and ions I'm not sure if a particle effect is the way to go here. What you typically see is strands of electricity writhing about in a static (pun not intended) manner, it will be very hard to obtain this kind of visual effect by using a particle system alone:

A lightning whip (C) Warren Martineck

Furthermore, it is advisable to use a particle system solely for visual effect, because it's expensive to check individual particle collisions in a lot of cases and you're better off simulating the associated gameplay effects in another way.[1]

So, if you haven't done so already, you should create the gameplay effect for the whip first, by applying the techniques mentioned in the answer to 2D Rope Collision Detection, but instead of drawing a rope, use the curve based on the resulting positions as a custom emitter for spark-like particles.

This way you get a whip which behaves the way you want to (based on the physics parameters), efficient collision detection with enemy spaceships and your desired lightning particle effect.

Update: If you just want to achieve the effect in Super Stardust Delta (as shown in the image you linked, and throughout this movie), you could have the whip curve emit brightly lit (in the case of the game: reddish) particles which die relatively quickly, and make sure they start out smaller the further along the curve they are away from the space ship.

Alternatively, to add more realistic "squiggles", instead of drawing a rope texture, use a variation of the technique described in the lightning whip movie I linked earlier:

  1. Get an animated lightning texture, something like this: lightning texture, preferably animated
  2. And draw it multiple times along the curve, making use of blending, distracting particle effects like this and animation offsetting to cover up transition areas.

Alter-alternatively, draw a number of curves instead of just one, using slightly perturbed points and different weight parameters, to simulate the lightning strands (giving an effect comparable to the image above). Though the result on itself won't be as chaotic as lightning usually looks, you might still be able to come up with a nice effect by tweaking the emitter to more erratically dispense the lightning sparks.

share|improve this answer
I'm not really sure how to do the sparks either, though. All I've managed to come up with are some squiggly lines that don't look very convincing at all. – Fibericon Apr 9 '12 at 9:12
The important things about sparks is that they're white in the inside and blue on the outside. If you're using particles for the sparks themselves, then you have to do this with a shader. You draw the particles in some special color, and use a pixel shader which colors the input pixel blue if one of their surrounding neighbour pixels has that special color && the adjacent neighbours of that pixel don't have that color, and white if the input pixel is that special color. Well that's the general algorithm that I just thought of right now, its probably not all correct but youll work it out. – TravisG Apr 9 '12 at 10:43
Just to make it clear: You're not drawing each particle with that shader, you draw the particles into an empty texture and run the shader over that texture, and then draw the resulting image at once. – TravisG Apr 9 '12 at 10:45
That would explain why it never looked right in the MPE editor. – Fibericon Apr 9 '12 at 10:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.