Advanced Particle Effects System

Started by
10 comments, last by helix 18 years, 9 months ago
Hello, I'm currently working on this game project that puts a heavy emphasis on particles. I have a pretty robust particle system already setup, but one of my effects is causing me trouble. I'm trying to get particles to emit from one emitter (in a directional cone) and fly around like normal before getting sucked into a point in space (implosion emitter). For instance, a particle will come out of the emitter. It will come out in an arc and then after the forces have stopped acting on it, it will get sucked into a point that is closest to the emitter it came from. I have tried using a "sphere of influence". Like a sphere that is based around the point where the implosion emitter is and I just do an inexpensive point-in-sphere test to determine if the particle is in the sphere, if it is then I send it on a straight line directly to the center of the sphere. What I would rather do is allow the particle to still fly in the direction it was originally going but make it gravate towards the center instead of flying directly at it. I think it would look better. Any ideas?
Advertisement
I don't think you need anything too fancy here, just to emulate some physics. Give your particles some vectors to hold their velocity and the sum of the forces that is currently acted uppon them. Then calculate their motion according to Newton Laws. For instance, for the case you're describing you would need to consider a force with the direction from the particle to the particle "sucker" and with strength=(Constant/R^2).


The above example is a little "hackish" and not too physically correct(I omitted masses,etc...) but I think it will give you an idea:

TVector blackhole;//Runs a "physic" system for the particle for a small interval dtvoid ProcessParticle(TParticle &part,float dt){TVector Force;float distance;Force=blackhole-part.position;//Get directiondistance=Force.length();Force.Normalize();//Set unit lengthForce=Force*(CONSTANT/(distance*distance));//Set strengthpart.velocity=part.velocity+Force*dt;//Increase velocitypart.position=part.position+part.velocity*dt;//Update position}


Of course, you will have to implement your own routines for vector math, or get them from a library.
At the point that the particle crosses the sphere, you should have:

CurrentVelocity - Direction vector pointing the direction it is travelling currenty.

TargetVelocity - Direction vector from current position to black hole

Just do an interpolation between the two each physics update. Maybe increase the length of the vector a small fraction each update as you get closer to the black hole to make it look as though it's speeding up, which it would if it was getting sucked in.

Right?

[edit]sorry, just noticed mikeman's response, which is essentially the same solution[/edit]
Thanks alot for the response. I've tried your ideas and they aren't working correctly. Maybe I'm doing something wrong.

When you say interpolation, do you mean adding the two vectors together?
Are they are really cool websites out there with ideas or already implemented advanced particle effects?
Quote:Original post by livingaftermidnight
When you say interpolation, do you mean adding the two vectors together?
No. He means a smooth transition between the two. If t varies from 0 to 1 over the time of the transition, then a simple interpolation can be done like this:

t*original_velocity plus (1-t)*final_velocity

(The page seems to be eating my plus sign :?)

You might also try a gravitic model, by calculating the vector from the particle to the implosion emitter at each update, and adding a velocity along that vector to the particle's existing velocity, scaling the added vector based on the length of time since the previous update.



How would you find that velocity along the new vector (from the particle to the implosion emitter)?

I'm not actually doing it with a timestep right now, it's just going as fast as it can, but I can freeze it and move it frame by frame with the spacebar. If it's going to be in a game it'll have to be timestepped i guess so i should change it.
Quote:Original post by livingaftermidnight
How would you find that velocity along the new vector (from the particle to the implosion emitter)?
You mean for the gravity-based emitter?
target_pos - current_pos
will give you a vector from the particle's current position to the implosion emitter. Normalize that, and then you can multiply the normalized vector by some constant to adjust the strength of the emitter's gravity. Then add that result to your particle's current velocity.

Figuring out the constant to multiply the normalized vectors by will take some trial and error.

That did it! Thank you so much! HELL YES!
Here is the final result. You can see the defined sphere edge on the explosion emitter.

This topic is closed to new replies.

Advertisement