Jump to content
  • Advertisement
Sign in to follow this  
Krun

Particle attractor

This topic is 5046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've never done a particle attractor before and would really like to implement one in my particle engine. I'm not really sure if I'm doing it right. Here's the main affect function of my basic attractor class: void nParticleAttractor::Affect(nIParticle* particle) { nVector2 dir = m_Position - particle->GetPosition(); nVector2 force = dir * (1.0f/(dir.Length()/2.0f)) * m_Power; particle->AddForce(force); } Is this corrent? Could some one give me an overview of how to create forcefields/attractors please. Here is my app Download Just uncomment the attractor actor in the Scene.xml file

Share this post


Link to post
Share on other sites
Advertisement
Quote:

nVector2 force = dir * (1.0f/(dir.Length()/2.0f)) * m_Power;

could be written as

nVector2 force = dir * Power(dir);


Where Power() is a function depending on the relative position of the particle.
E.g. if you have two masses attracting each other, newtons law is:

F= gamma*m1*m2/(r*r)

so your Power() function would look like this:

float Power(nVector2 dir)
{
float c = ...; // some constant, i.e. gamma*m1*m2
float l = dir.Length();
return c / (l*l);
}


but you could use any other function you like.

Got the idea ?

Share this post


Link to post
Share on other sites
note that:

scale = 1.0f / (tiny_offset + dot_product (dir, dir));
particle->AddForce (dir * Scale);

is faster, no square root. but that may not be the function you want.

tiny_offset is to bypass 1/0 without if statements, of course.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!