1
\$\begingroup\$

This question already has an answer here:

I have a simple particle game, where all the particles are arranged in a grid. This game is for touch devices so to take advantage of it I am trying to have a multitouch gravity field thing going on.

Basically I am trying to get it so that each finger is basically a well in an otherwise non existent gravity field. That way the particles are pulled towards a finger.

My problem is I don't even know where to begin with these calculations, I have tried averaging a particles distance to each finger, its direction to each finger and nothing seems to work nicely!

I have seen other games do this. What does the math for it look like?

\$\endgroup\$

marked as duplicate by congusbongus, Almo, Josh May 31 '16 at 17:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2
\$\begingroup\$

This is in no way a complete answer.

What you could try is: for each finger touching the interface, you calculate the distance and direction of each particle from the touch point.

With the distance, you compute a force (use x as input, and have y result in something based on a logarithm or square function: the closer to the well, the stronger the force).

Add the velocity, composed of the direction and the force, to the particle.

Repeat for each finger!

\$\endgroup\$
  • \$\begingroup\$ How do you avoid having more forces when their are more fingers? \$\endgroup\$ – J.Doe May 27 '16 at 1:52
  • 1
    \$\begingroup\$ You don't! 2 fingers -> 2 wells -> twice the attracting force! Particles caught in the middle should stay still! \$\endgroup\$ – Alexandre Vaillancourt May 27 '16 at 1:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.