Find out my DRAG speed

Hi everyone!
hope you can help me out… i can’t for the life of me think of a way to get the drag speed!

i am dragging an object throughout the screen but i would like to slow down the speed of the drag if it collides into certain objects.

  1. can i control the speed of drag?
  2. if 1 isn’t possible is there a way to find the speed in which i am dragging the object on any x or y coord?

any clues or advice would be great!

Thanks for your time! [import]uid: 99036 topic_id: 23944 reply_id: 323944[/import]

the answer is it depends … :slight_smile:
it depends on how you are dragging the object around…
but you can get the speed by storing the current position of the object per frame, then with each new frame (or move event or whatever) compare the new position with your stored position. the difference between the two is your speed in x and y over the time you have tested…

eg. in your touch function…

[lua]…

– somewhere global…
local lastX = 0
local lastY = 0

if(event.phase == “began”) then
– store the start position
lastX = event.x
lastY = event.y

elseif(event.phase == “moved”) then
local dx = event.x - lastX
local dy = event.y - lastY
local speed = sqrt(dx*dx + dy*dy)
lastX = event.x
lastY = event.y --don’t forget to update…
end[/lua]

to restrict the drag speed, you need to limit how much the object you are draggin moves per frame… which depends a lot on how you are moving it around!
hope that gives you some pointers
[import]uid: 118333 topic_id: 23944 reply_id: 96489[/import]

This is great ill try that out asap!

Thanks for the info!
[import]uid: 99036 topic_id: 23944 reply_id: 96594[/import]