Skip to main content
gamedev.net
🔒 Locked

Particle attractor

Started by Krun Nov 28, 2004 at 2:22 PM 1 replies 2.3k views
Original Post
Krun
Krun
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
nmi
nmi
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 ?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.