Help with code for transition.to with moving boards.

Hi all,

I’m currently working on a game ‘Magnet Monsters’ please see link to tweet to see the demo of the game so far.

https://twitter.com/playhousegamer/status/1215953580131266560

There are 2 boards moving across the screen at the same time using transition.to. When you move between the boards they stop and start again when you land. The transition.to starts again so if you’re very close to the edge it still uses up the 1000 to only go a short distance which doesn’t make for great gameplay!

Is there a way to always make the boards move at the same speed even after they’ve stopped and started again? I was thinking of using the system time but am not sure how to do this. All help appreciated. Transition.to code below.

 function moveTopBlock() topblock.transition = transition.to(topblock,{time = 1000,x = \_CW-topblock.width/2, onComplete = trans2}) end trans2 = function () topblock.transition = transition.to(topblock,{time = 1000,x = 0+topblock.width/2, onComplete = moveTopBlock}) end

I’ve also attached the .mov but not sure if that uploads so have included link.

Many thanks

Matt

Hi @matthewhanc,

Try

function moveTopBlock() local total\_time = 1000 local total\_distance = \_CW - topblock.width local const\_velocity = total\_distance/total\_time local new\_distance = total\_distance + topblock.width/2 - topblock.x local new\_time = new\_distance/const\_velocity    topblock.transition = transition.to(topblock,{time = new\_time,x = \_CW-topblock.width/2, onComplete = trans2})  end      trans2 = function ()       topblock.transition = transition.to(topblock,{time = 1000,x = 0+topblock.width/2, onComplete = moveTopBlock}) end

Can you use transition.pause and transition.resume?

Have a nice day:)

ldurniat

Hi @idurniat,

Thank you so much for your help! The code works very well, as soon as I read it I thought ‘why didn’t I think of that!’ I’ve posted a new tweet for the Saturday Game Dev. Please see link below, the game flows so much better now.

https://twitter.com/playhousegamer/status/1216134679662821377

I no doubt will be back on the forum as I am now noodling adding in new monsters as you progress through the levels. I’ll see what my brain can process first!

Many thanks

Matt