I have a question, I need a formula to calculate the distance and a force based on the speed that drags the finger up on the phone. And is there any way I can get a look? And also shows the trajectory of the ball with lines ...

An example is the Pokemon Go, see the image (the user presses the ball and drags the finger upwards).

enter image description here

Are there any examples so that I can study?


1 Answer 1


This can be done by measuring the distance between the touch and release point. Along with measuring the time difference from when the touch started until the release happened.

Then simply take the distance and divide it with the time, and this would give you a relative force.

To give the general idea:

clock = new THREE.Clock();

function onTouch(event) {
    startTime = clock.getElapsedTime();
    startPosition = new THREE.Vector3(e.clientX, "y": e.clientY);

function onRelease() {
    endTime = clock.getElapsedTime();
    endPosition = new THREE.Vector3(e.clientX, "y": e.clientY);

    diff = startPosition.copy().sub(endPosition.x);
    distance = diff.length();

    // Remember to check if endTime > startTime
    force = distance / (endTime - startTime);

    // Then multiply the force by some factor and apply it

onTouch() being called when the touch begins and onRelease() begin called when it ends.

Since you already have the touch and release points, you can calculate the angle of the flick. Then project that according to some other vector you have deciding the orientation of the phone in this case.

For getting the trajectory of the path you apply force to an object and simulate it for a n steps tracking the position. After that draw a line between the collected positions.

For an existing project take a look at ezartech/pokemon-go-experiment.

  • \$\begingroup\$ But in this case player will be able to just touch and release finger without sliding right? \$\endgroup\$
    – Nick
    Commented Jun 28, 2017 at 5:58
  • \$\begingroup\$ True, however given that we also include the time from when the touch started, that means that sliding really slow would result in a smaller force. \$\endgroup\$
    – vallentin
    Commented Jun 30, 2017 at 17:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .