Sign in to follow this  
livingaftermidnight

Advanced Particle Effects System

Recommended Posts

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?

Share this post


Link to post
Share on other sites
mikeman    2942
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 dt
void ProcessParticle(TParticle &part,float dt)
{
TVector Force;
float distance;

Force=blackhole-part.position;//Get direction
distance=Force.length();
Force.Normalize();//Set unit length
Force=Force*(CONSTANT/(distance*distance));//Set strength

part.velocity=part.velocity+Force*dt;//Increase velocity
part.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.

Share this post


Link to post
Share on other sites
Chris81    196
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]

Share this post


Link to post
Share on other sites
yckx    1298
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.



Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
yckx    1298
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.

Share this post


Link to post
Share on other sites
yckx    1298
Quote:
Original post by livingaftermidnight
That did it! Thank you so much! HELL YES!

Glad to help. This just goes to show that I can explain concepts better than I can code :P

Share this post


Link to post
Share on other sites
helix    301
Just start adding a force to the particle in the direction of the implosion emitter. You could also maybe add the effect of scaling this force based on the distance from the emitter (and perhaps even using your sphere as a threshold and/or as the scaling factor).

edit: I guess that's already been mentioned

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this