actionscript 3 - Can't stop the particles from overshooting -


i trying create simple particle simulation. there 2 types of particles static , moving. static particles attract moving particles towards centre. static particles have strength attribute dictates how hard pulling moving particles

var angle:number = math.atan2(moving.y - static.y , moving.x - static.x); var dist = point.distance(new point(moving.x,moving.y) , new point(static.x,static.y));  moving.velx += math.cos(angle + math.pi) * static.strength / dist; moving.vely += math.sin(angle + math.pi) * static.strength / dist; 

the problem when particle passing through centre distance small results in large velocity values.

i added check distance before calculating velocity.

if (dist < 1)     dist = 1; 

but problem still persists. cant figure out problem.

here snapshot of overshoot happening.

enter image description here

normal force fields use square of distance modifier, here use single power of distance, of course force field performs differently. should change var dist line following:

var dist:number = (moving.x-static.x)*(moving.x-static.x) + (moving.y-static.y)*(moving.y-static.y); 

this way dist hold square of actual distance, dividing dist give proper force field configuration.

and, please rename static, it's reserved word in as3.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -