Ok I have a particle system going in Android.
Right now I use 500 or so particles and they randomly move around the screen. I set it so that on touch (actually motion right now). that all the particles would approach your finger. Problem being is that they’re approaching at a static angle (not taking into the angle they are from the touch point).
Anyone have the algorithm to determine how to evenly approach a point? My attempt to get the angle in randians.. then convert etc.. got really messy. This simple approach showed that I move at the right pace.. but it’s a simple 45 angle approach. (keep in mind on android there are no negative x,y coordinates.. and top left is 0,0.. bottom right is (max,max). the functions takes the ontouch (x,y) coordinates. b.x, b.y are the particle coordiantes.
public void moveParticles(float x, float y) {
for (Particle b : Particles)
{
if (x <= b.x)
b.x = b.x -1;
else b.x = b.x +1;
if (y <= b.y)
b.y = b.y -1;
else b.y = b.y +1;
}
}
Naive code that assumes touch is in the centre of the screen:
Code with normalised speeds each side of the touch axis:
Steps to make this code:
You need to get the ratio of the screen above and below the x and y axis, so as to normalise the speed of the particles from 0 to 1 no matter where the touch is:
Once we have that normalisation information we can use it to normalise the particle speeds: