Getting coordinates of object in the past

I’m quite new to programming and lua so i’m not sure I can explain this well. I’m creating a feature in my 2D platformer game where the character can be teleported sort of back in time. For example, teleporting it where it was 3 seconds ago. I assume there’s no handy function to just get coordinates 3 seconds ago, but I’ve only come up with saving coordinates every 0.1s in a table in enterFrame function and then deleting them after 3 seconds have passed. Anyways, this method would probably considerably slow down mobile devices and would be a hassle to code. Any suggestions are highly appreciated!

Hello,

I made the same program a week ago, and I use the same method as you : to save the data in a table each frame, and then delete it after a time.

I think it’s the more easy way to do.

Hey yvandotet,

 

Could you possibly share your code of how you manage the table? Sadly, I have no experience with timers and tables  :(. 

 

Big thanks for you help  :slight_smile:

I don’t have the code yet, but it’s easy to do.

I made one quickly, where a ball drop on the top left with a tiny speed, and touch the ground.

To comeback to the past, tap the screen.

I fill the table " tab " with coordonnate each 300 milliseconds, and when I tap the screen, a series of transition happens to go to the last place where the user tap.

It’s just an idea.

//the object local ball=display.newCircle(0,0,30) physics.addBody(ball,{radius=30}) ball:setLinearVelocity(100,0) //the ground local ground=display.newRect(display.contentCenterX,display.contentCenterY,300,10) physics.addBody(ground,"static") //to fill the ball.x and ball.y local tab={} function ball.pastCoordonate()   local o=ball   table.insert(tab,{o.x,o.y}) end local timeChecking=300 local checkTimer=timer.performWithDelay(timeChecking,ball.pastCoordonate,-1) local isTap local function retour(event)   if not isTap then isTap=true          timer.pause(checkTimer)     local cumul=0     for k=#tab,2,-1 do       transition.to(ball,{time=100,delay=cumul,x=tab[k][1],y=tab[k][2]})       cumul=cumul+100       table.remove(tab,k)     end          if #tab==0 then return end          transition.to(ball,{time=100,delay=cumul,x=tab[1][1],y=tab[1][2],         onComplete=function()           timer.resume(checkTimer)           isTap=false           ball:setLinearVelocity(100,0) end})     table.remove(tab,1)                  end end Runtime:addEventListener("tap",retour)

Hello,

I made the same program a week ago, and I use the same method as you : to save the data in a table each frame, and then delete it after a time.

I think it’s the more easy way to do.

Hey yvandotet,

 

Could you possibly share your code of how you manage the table? Sadly, I have no experience with timers and tables  :(. 

 

Big thanks for you help  :slight_smile:

I don’t have the code yet, but it’s easy to do.

I made one quickly, where a ball drop on the top left with a tiny speed, and touch the ground.

To comeback to the past, tap the screen.

I fill the table " tab " with coordonnate each 300 milliseconds, and when I tap the screen, a series of transition happens to go to the last place where the user tap.

It’s just an idea.

//the object local ball=display.newCircle(0,0,30) physics.addBody(ball,{radius=30}) ball:setLinearVelocity(100,0) //the ground local ground=display.newRect(display.contentCenterX,display.contentCenterY,300,10) physics.addBody(ground,"static") //to fill the ball.x and ball.y local tab={} function ball.pastCoordonate()   local o=ball   table.insert(tab,{o.x,o.y}) end local timeChecking=300 local checkTimer=timer.performWithDelay(timeChecking,ball.pastCoordonate,-1) local isTap local function retour(event)   if not isTap then isTap=true          timer.pause(checkTimer)     local cumul=0     for k=#tab,2,-1 do       transition.to(ball,{time=100,delay=cumul,x=tab[k][1],y=tab[k][2]})       cumul=cumul+100       table.remove(tab,k)     end          if #tab==0 then return end          transition.to(ball,{time=100,delay=cumul,x=tab[1][1],y=tab[1][2],         onComplete=function()           timer.resume(checkTimer)           isTap=false           ball:setLinearVelocity(100,0) end})     table.remove(tab,1)                  end end Runtime:addEventListener("tap",retour)