Transition.to with speed not time

Hello everyone!

I am trying to transition an ship to the point i click/touch and it works good except that in long distances it travels very fast and in short it travels very slow. This is because of the time attribute but i want it to travel at the same speed no matter the distance, is this possible?

Or is this just stupid to try to accomplish?

Hope someone know how to do this:)

Kind Regards:) [import]uid: 90942 topic_id: 23055 reply_id: 323055[/import]

Can you post up your transition.to code for the ship please? [import]uid: 84637 topic_id: 23055 reply_id: 92171[/import]

Create a variable that multiplies your time by your distance. Use that for your time unit in your transistion.

So let’s say it takes 1 second to travel across a short distance. If you assign a value to that distance, say 100 pixels, when you want the object to transition 500 pixels you simply set your time variable/value to 1 X 5.

100 pixels = 1(sec) * 1(distance) = 1 second
500 pixels = 1(sec) * 5(distance) = 5 seconds [import]uid: 64596 topic_id: 23055 reply_id: 92176[/import]

Hey Shane!

I don’t really understand, how can i find out the distance? Is there an easy way to find it out from there the ship is to the touched place?

Have been trying to figure it out but just can’t get my head around it:(

It could probarly solve it if i could manage to get a distance between ship.x, ship.y and touched event.x, touched event.y but i just don’t get it.

Kind regards [import]uid: 90942 topic_id: 23055 reply_id: 92203[/import]

Hej Danny!

What i have so far is:

local shipListener = function(e)

if(e.phase == “began”) then

transition.to(ship, {time=800, x=e.x, y=e.y, easing.linear})

end

end

Runtime:addEventListener(“touch”, shipListener)

/Inkoqnito [import]uid: 90942 topic_id: 23055 reply_id: 92204[/import]

In your touch-receiving function:

the x difference/distance in pixels = math.abs(event.x - ship.x)
the y difference/distance in pixels = math.abs(event.y - ship.y)

Using math.abs will give you a positive number regardless of the direction.

The total distance then would be:

distance (in pixels) = math.sqrt((x difference * x difference) + (y difference * y difference)) [import]uid: 64596 topic_id: 23055 reply_id: 92210[/import]