gravity in a particle system
in
Programming Questions
•
2 years ago
i guys i've tried to implement a simple particle system
i've got a Circle class with location, position and acceleration PVector
and this method:
- void gravity() {
- for(int i=0; i<particles.length; i++) {
- Circle body = particles[i];
- PVector attractor = new PVector(mouseX, mouseY); //center of attraction
- PVector between = PVector.sub( attractor, body.location); //distance vector
- float distBetween = between.mag(); //distance value
- if(distBetween>=60) { // ###
- distBetween=60;
- }
- between.normalize(); // why?? because i have subtracted?
- float force = (50 * body.radius ) / (distBetween*distBetween); // newton gravity formula
- between.mult(force); // why not normilizing again?
- body.velocity.add(between);
- }
- }
and i'm gaining - dont know why - a "spring" linke movement:
particles get mouseX and mouseY coordination but oltrepass it and come back in a circular way,
and sometimes (there are ranodm initial velocity) orbit around it
.. but i'm adding gravity vector on velocity, not accellaration (as in spring formula!)
i thought that if gravity is too strong is bad, and so i put the if condition (###):
no more absurde velocity but if i left particles goes on for minutes the never achive mouseX,mouseY..
1