Moving object stops when getting out of screen

Hello everybody, I’m having another little issue with MTE.
 
Basically, I display a robot imageSheet, and move it with the setLinearVelocity function. When it collides on the left or on the right with a floor tile (grass), it just reverses its xScale as well as its LinearVelocity.
 
Everything works perfectly. The problem is that when it goes out of the screen, it stops moving. Since it’s not possible not to stop its movement, because it would fall when the tiles are removed, I would like to know if there’s any way to resume its movement when it goes in the screen boundaries again, or any solution ?
 
Video :

https://www.youtube.com/watch?v=ug3zwVvIuq4

Thanks you very much !

If you set the sprite’s offscreenPhysics property to true, either directly by sprite.offscreenPhysics = true or as a parameter in it’s setup table, the sprite will generate a tiny area of map around itself no matter where it is in relation to the screen. It’ll be able to continue moving in any direction to any place without falling through the world.

Didn’t know about this one, it’s awesome ! Thanks you Dyson ! I have a last issue for the moment : ghost edges that stops the enemy and the player from moving… You surely know what I’m talking about. When I place individual tiles with physic bodies, sometimes the physic bodies are not placed correctly, there can be a 1px space which causes the player the stop. Currently, I’m following the solution you provided in another topic, which is to adjust the bounce property. Sometimes it works, sometimes it doesn’t. Sometimes it even stops the player a few milliseconds and resumes the movement. Can you help me with that ?

I’ve posted a video demonstrating the best solution so far to this problem here: http://forums.coronalabs.com/topic/33119-million-tile-engine-beta-release/?p=242414

Works nicely, only for the enemies though. The player bounces a little bit when walking on a platform. But there are really strange issues with offscreenPhysics : as the tiles around the enemies are removed, it makes the enemies fall down through the platform, just like in this video :

http://youtu.be/TT_vkmWcDRM

Hmm, one of my performance optimizations isn’t working correctly. The offscreen objects only alter their tiny map regions when their locations change. However the camera will cull tiles as it normally does, and when the objects are close to the edge of the view their regions are culled- until their location changes again. With your enemies walking as slowly as they do they have ample time to fall through the culled floor.

I’m still working the problem on my end. In the meantime you can kill the optimization by going to line 9295 and killing that if-then check:

if not object.bounds or (object.bounds[1] ~= left or object.bounds[2] ~= top or object.bounds[3] ~= right or object.bounds[4] ~= bottom) then if object.physicsRegion then for p = 1, #object.physicsRegion, 1 do local lx = object.physicsRegion[p][1] local ly = object.physicsRegion[p][2] if (lx \< masterGroup[i].vars.camera[1] or lx \> masterGroup[i].vars.camera[3]) or (ly \< masterGroup[i].vars.camera[2] or ly \> masterGroup[i].vars.camera[4]) then updateTile2({locX = object.physicsRegion[p][1], locY = object.physicsRegion[p][2], layer = object.physicsRegion[p][3], tile = -1, owner = object }) end end end object.physicsRegion = nil object.physicsRegion = {} for lx = left, right, 1 do for ly = top, bottom, 1 do for j = 1, #map.layers, 1 do if (lx \< masterGroup[j].vars.camera[1] or lx \> masterGroup[j].vars.camera[3]) or (ly \< masterGroup[j].vars.camera[2] or ly \> masterGroup[j].vars.camera[4]) then local owner = updateTile2({locX = lx, locY = ly, layer = j, onlyPhysics = false, owner = object}) if owner then object.physicsRegion[#object.physicsRegion + 1] = {lx, ly, j} end end end end end object.bounds = {left, top, right, bottom} end

--if not object.bounds or (object.bounds[1] ~= left or object.bounds[2] ~= top or object.bounds[3] ~= right or object.bounds[4] ~= bottom) then --comment out if object.physicsRegion then for p = 1, #object.physicsRegion, 1 do local lx = object.physicsRegion[p][1] local ly = object.physicsRegion[p][2] if (lx \< masterGroup[i].vars.camera[1] or lx \> masterGroup[i].vars.camera[3]) or (ly \< masterGroup[i].vars.camera[2] or ly \> masterGroup[i].vars.camera[4]) then updateTile2({locX = object.physicsRegion[p][1], locY = object.physicsRegion[p][2], layer = object.physicsRegion[p][3], tile = -1, owner = object }) end end end object.physicsRegion = nil object.physicsRegion = {} for lx = left, right, 1 do for ly = top, bottom, 1 do for j = 1, #map.layers, 1 do if (lx \< masterGroup[j].vars.camera[1] or lx \> masterGroup[j].vars.camera[3]) or (ly \< masterGroup[j].vars.camera[2] or ly \> masterGroup[j].vars.camera[4]) then local owner = updateTile2({locX = lx, locY = ly, layer = j, onlyPhysics = false, owner = object}) if owner then object.physicsRegion[#object.physicsRegion + 1] = {lx, ly, j} end end end end end object.bounds = {left, top, right, bottom} --end --comment out

A huge “Thanks you” for this answer. I’ve been scratching my head without success on this issue.

If you set the sprite’s offscreenPhysics property to true, either directly by sprite.offscreenPhysics = true or as a parameter in it’s setup table, the sprite will generate a tiny area of map around itself no matter where it is in relation to the screen. It’ll be able to continue moving in any direction to any place without falling through the world.

Didn’t know about this one, it’s awesome ! Thanks you Dyson ! I have a last issue for the moment : ghost edges that stops the enemy and the player from moving… You surely know what I’m talking about. When I place individual tiles with physic bodies, sometimes the physic bodies are not placed correctly, there can be a 1px space which causes the player the stop. Currently, I’m following the solution you provided in another topic, which is to adjust the bounce property. Sometimes it works, sometimes it doesn’t. Sometimes it even stops the player a few milliseconds and resumes the movement. Can you help me with that ?

I’ve posted a video demonstrating the best solution so far to this problem here: http://forums.coronalabs.com/topic/33119-million-tile-engine-beta-release/?p=242414

Works nicely, only for the enemies though. The player bounces a little bit when walking on a platform. But there are really strange issues with offscreenPhysics : as the tiles around the enemies are removed, it makes the enemies fall down through the platform, just like in this video :

http://youtu.be/TT_vkmWcDRM

Hmm, one of my performance optimizations isn’t working correctly. The offscreen objects only alter their tiny map regions when their locations change. However the camera will cull tiles as it normally does, and when the objects are close to the edge of the view their regions are culled- until their location changes again. With your enemies walking as slowly as they do they have ample time to fall through the culled floor.

I’m still working the problem on my end. In the meantime you can kill the optimization by going to line 9295 and killing that if-then check:

if not object.bounds or (object.bounds[1] ~= left or object.bounds[2] ~= top or object.bounds[3] ~= right or object.bounds[4] ~= bottom) then if object.physicsRegion then for p = 1, #object.physicsRegion, 1 do local lx = object.physicsRegion[p][1] local ly = object.physicsRegion[p][2] if (lx \< masterGroup[i].vars.camera[1] or lx \> masterGroup[i].vars.camera[3]) or (ly \< masterGroup[i].vars.camera[2] or ly \> masterGroup[i].vars.camera[4]) then updateTile2({locX = object.physicsRegion[p][1], locY = object.physicsRegion[p][2], layer = object.physicsRegion[p][3], tile = -1, owner = object }) end end end object.physicsRegion = nil object.physicsRegion = {} for lx = left, right, 1 do for ly = top, bottom, 1 do for j = 1, #map.layers, 1 do if (lx \< masterGroup[j].vars.camera[1] or lx \> masterGroup[j].vars.camera[3]) or (ly \< masterGroup[j].vars.camera[2] or ly \> masterGroup[j].vars.camera[4]) then local owner = updateTile2({locX = lx, locY = ly, layer = j, onlyPhysics = false, owner = object}) if owner then object.physicsRegion[#object.physicsRegion + 1] = {lx, ly, j} end end end end end object.bounds = {left, top, right, bottom} end

--if not object.bounds or (object.bounds[1] ~= left or object.bounds[2] ~= top or object.bounds[3] ~= right or object.bounds[4] ~= bottom) then --comment out if object.physicsRegion then for p = 1, #object.physicsRegion, 1 do local lx = object.physicsRegion[p][1] local ly = object.physicsRegion[p][2] if (lx \< masterGroup[i].vars.camera[1] or lx \> masterGroup[i].vars.camera[3]) or (ly \< masterGroup[i].vars.camera[2] or ly \> masterGroup[i].vars.camera[4]) then updateTile2({locX = object.physicsRegion[p][1], locY = object.physicsRegion[p][2], layer = object.physicsRegion[p][3], tile = -1, owner = object }) end end end object.physicsRegion = nil object.physicsRegion = {} for lx = left, right, 1 do for ly = top, bottom, 1 do for j = 1, #map.layers, 1 do if (lx \< masterGroup[j].vars.camera[1] or lx \> masterGroup[j].vars.camera[3]) or (ly \< masterGroup[j].vars.camera[2] or ly \> masterGroup[j].vars.camera[4]) then local owner = updateTile2({locX = lx, locY = ly, layer = j, onlyPhysics = false, owner = object}) if owner then object.physicsRegion[#object.physicsRegion + 1] = {lx, ly, j} end end end end end object.bounds = {left, top, right, bottom} --end --comment out

A huge “Thanks you” for this answer. I’ve been scratching my head without success on this issue.