Does the above function not give you the same speed for your balls? Let me try to explain:
You can’t really save the “speed” of the ball because that is actually the time it takes for the transition to complete itself. Let’s say in your first example you clicked 200 pixels away so the time would be 2 seconds to reach destination. But then the next touch you click only 50 pixels away, therefor you cannot use the “speed” from before since it traveled 200 pixels in 2 seconds, now it will only travel 50 pixels in 2 seconds making it look like the speed is a quarter of what it was before. That is why we gave iit a formula so that it calculates it for each individual touch, to make the speed always be the same. Does it not work?
function shoot(event)
i = i + 1
if (i == 1) then
speedBallX1 = math.abs(event.x - ball1.x)
speedBallY1 = math.abs(event.y - ball1.y)
speedBall1 = (math.pow(speedBallX1, 2)) + (math.pow(speedBallY1, 2))
speedBall1 = math.sqrt(speedBall1)
transition.to( ball1, { time = (speedBall1\*10), x=event.x, y=event.y } )
elseif (i == 2) then
transition.to( ball1, { time = math.abs((event.x - ball1.x)\*10), x=event.x, y=event.y } )
transition.to( ball2, { time = math.abs((event.x - ball2.x)\*10), x=event.x, y=event.y } )
elseif (i == 3) then
transition.to( ball1, { time = math.abs((event.x - ball1.x)\*10), x=event.x, y=event.y } )
transition.to( ball2, { time = math.abs((event.x - ball2.x)\*10), x=event.x, y=event.y } )
transition.to( ball3, { time = math.abs((event.x - ball3.x)\*10), x=event.x, y=event.y } )
end
end
I revamped your code a little bit because I forgot entirely about the Y axis. However I only added it for ball1 as to not confuse you with adding to much code. It uses pythagora’s formula to calculate the proper time so both axis’s works. Hope it works and is not confusing. Anyway, did you test your above function and the speeds were incorrect? Or what are you trying to achieve exactly [import]uid: 77199 topic_id: 36434 reply_id: 144711[/import]