# Velocity and Swipe Distance

#1

Can someone help me make a code that determines how far something will go like for instance throwing a ball by calculating the velocity and y position when you swipe?

@Funky_63_Greenland do u have any ideas?

#2

Like if I swipe really fast and my finger goes across the screen… I’d want the object to go very far but if I barley swipe I’d want it to just barley go anywhere just like in real life

#3

I could probably figure it out.

I’ll do it later.

#4

u could do somthing with tracking the distanve of an object with folow finger

#5

Yea that was what I’m doing

#6

What’s a code for velocity?

#7

Variable tracking time and one tracking distance.

#8

I don’t really know how to do that, but I think that it is possible.

#9

I HAVE NO IDEA ABOUT ANY OF THIS BECAUSE I AM A TERRIBLE CODER so yea.

#10

@LegendOfFriday I can certainly help you. But can you explain a bit more about what you want to do?

Speed is just distance / time. Many times people say velocity when, technically, they mean speed. Velocity is a vector whereas Speed is a scalar. That just means speed is a number and velocity is a number & direction (i.e., angle).

So, for example, is the mechanic you want 1D or 2D? 1D would be straight line movement. 2D would be horizontal or vertical movement on the screen and might or might not include gravity. The better you explain what you’re trying to do, the easier it is to help you.

#11

@LegendOfFriday

Try this. I made a custom rule for 'Flick to Move’

Is this what you were looking for?

It works by continually checking the distance you’ve moved your finger while the object is pressed. That distance is actually a speed as it’s distance per 16.7ms (when the Hopscotch player is running at 60fps). It tracks the maximum speed, then when the Press is released it sets the object’s angle pointing towards the last touch location and moves the object a distance that’s a factor of the max speed you swiped.

The distance per frame is worked out by continually setting 2 object variables to the last touch location which become the last touch location of the previous frame. Then the distance between the current and previous last touch locations is calculated using Pythagorean theorem (A^2 + B^2 = C^2)