Transition.to question

I have 3 objects that travel to a point I touch through the “transition.to” API. The trouble is the objects will travel at different speeds depending on the distance from the touch point because of the timer like here:

transition.to( ball1, { time=1500, x=event.x, y=event.y } )

What I would like is to have objects travel at the same speed, something like this:

transition.to( ball1, { speed=100pixels/second, x=event.x, y=event.y } )

But the “speed=100pixels/second” doesn’t exist. Can someone recommend the correct way to do this, thanks!

[import]uid: 75779 topic_id: 36434 reply_id: 336434[/import]

Sounds like time is the speed in this case.

For example if your ball.x is 150 and you touch on 250 that means it’s going to travel 100 pixels. You want 100 pixels per sec so it would go like this

transition.to( ball1, { time = math.abs((event.x - ball1.x)\*10), x=event.x, y=event.y } )  

[import]uid: 77199 topic_id: 36434 reply_id: 144637[/import]

Thank you for assistance! To furthur our discussion can you recommend a way to lock in the value in (i=1) So that on all subsequent touches the locked in speed will be the speed for all other balls on all other touches? Thanks!

[lua]
function shoot (event)
i = i + 1
if (i == 1) then
transition.to( ball1, { time = math.abs((event.x - ball1.x)*10), x=event.x, y=event.y } )
end
if (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 } )
end
if (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
[/lua] [import]uid: 75779 topic_id: 36434 reply_id: 144676[/import]

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]

Thank you it works perfectly! That is very advanced what you did with math.abs, math.pow, and math.sqrt. Im curious how did you know this? This is similar to Pthygaris a2+b2=c2 ?

[import]uid: 75779 topic_id: 36434 reply_id: 144722[/import]

Glad it works. And yes it is pythagora’s a2 + b2 = c2 so it’s really not that advanced. math.pow sets it to the power of 2 so c = a2 + b2, and then I use sqrt to get the real value of C. math.abs sets the number to be always positive in case your ball is at 250 pixels and you click way to the left, lets say 50 pixels. It would be 50 - 250 = -200. math.abs just sets it to 200. Probably from being around the forums so much and reading all kinds of things, you pick up small things like this. Also this is something I implemented in a game at the beginning for learning purposes. Anyway glad it works and gl with the rest of your game [import]uid: 77199 topic_id: 36434 reply_id: 144728[/import]

Sounds like time is the speed in this case.

For example if your ball.x is 150 and you touch on 250 that means it’s going to travel 100 pixels. You want 100 pixels per sec so it would go like this

transition.to( ball1, { time = math.abs((event.x - ball1.x)\*10), x=event.x, y=event.y } )  

[import]uid: 77199 topic_id: 36434 reply_id: 144637[/import]

Thank you for assistance! To furthur our discussion can you recommend a way to lock in the value in (i=1) So that on all subsequent touches the locked in speed will be the speed for all other balls on all other touches? Thanks!

[lua]
function shoot (event)
i = i + 1
if (i == 1) then
transition.to( ball1, { time = math.abs((event.x - ball1.x)*10), x=event.x, y=event.y } )
end
if (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 } )
end
if (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
[/lua] [import]uid: 75779 topic_id: 36434 reply_id: 144676[/import]

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]

Thank you it works perfectly! That is very advanced what you did with math.abs, math.pow, and math.sqrt. Im curious how did you know this? This is similar to Pthygaris a2+b2=c2 ?

[import]uid: 75779 topic_id: 36434 reply_id: 144722[/import]

Glad it works. And yes it is pythagora’s a2 + b2 = c2 so it’s really not that advanced. math.pow sets it to the power of 2 so c = a2 + b2, and then I use sqrt to get the real value of C. math.abs sets the number to be always positive in case your ball is at 250 pixels and you click way to the left, lets say 50 pixels. It would be 50 - 250 = -200. math.abs just sets it to 200. Probably from being around the forums so much and reading all kinds of things, you pick up small things like this. Also this is something I implemented in a game at the beginning for learning purposes. Anyway glad it works and gl with the rest of your game [import]uid: 77199 topic_id: 36434 reply_id: 144728[/import]

Sounds like time is the speed in this case.

For example if your ball.x is 150 and you touch on 250 that means it’s going to travel 100 pixels. You want 100 pixels per sec so it would go like this

transition.to( ball1, { time = math.abs((event.x - ball1.x)\*10), x=event.x, y=event.y } )  

[import]uid: 77199 topic_id: 36434 reply_id: 144637[/import]

Thank you for assistance! To furthur our discussion can you recommend a way to lock in the value in (i=1) So that on all subsequent touches the locked in speed will be the speed for all other balls on all other touches? Thanks!

[lua]
function shoot (event)
i = i + 1
if (i == 1) then
transition.to( ball1, { time = math.abs((event.x - ball1.x)*10), x=event.x, y=event.y } )
end
if (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 } )
end
if (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
[/lua] [import]uid: 75779 topic_id: 36434 reply_id: 144676[/import]

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]

Thank you it works perfectly! That is very advanced what you did with math.abs, math.pow, and math.sqrt. Im curious how did you know this? This is similar to Pthygaris a2+b2=c2 ?

[import]uid: 75779 topic_id: 36434 reply_id: 144722[/import]

Glad it works. And yes it is pythagora’s a2 + b2 = c2 so it’s really not that advanced. math.pow sets it to the power of 2 so c = a2 + b2, and then I use sqrt to get the real value of C. math.abs sets the number to be always positive in case your ball is at 250 pixels and you click way to the left, lets say 50 pixels. It would be 50 - 250 = -200. math.abs just sets it to 200. Probably from being around the forums so much and reading all kinds of things, you pick up small things like this. Also this is something I implemented in a game at the beginning for learning purposes. Anyway glad it works and gl with the rest of your game [import]uid: 77199 topic_id: 36434 reply_id: 144728[/import]

Sounds like time is the speed in this case.

For example if your ball.x is 150 and you touch on 250 that means it’s going to travel 100 pixels. You want 100 pixels per sec so it would go like this

transition.to( ball1, { time = math.abs((event.x - ball1.x)\*10), x=event.x, y=event.y } )  

[import]uid: 77199 topic_id: 36434 reply_id: 144637[/import]

Thank you for assistance! To furthur our discussion can you recommend a way to lock in the value in (i=1) So that on all subsequent touches the locked in speed will be the speed for all other balls on all other touches? Thanks!

[lua]
function shoot (event)
i = i + 1
if (i == 1) then
transition.to( ball1, { time = math.abs((event.x - ball1.x)*10), x=event.x, y=event.y } )
end
if (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 } )
end
if (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
[/lua] [import]uid: 75779 topic_id: 36434 reply_id: 144676[/import]

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]

Thank you it works perfectly! That is very advanced what you did with math.abs, math.pow, and math.sqrt. Im curious how did you know this? This is similar to Pthygaris a2+b2=c2 ?

[import]uid: 75779 topic_id: 36434 reply_id: 144722[/import]