Basic Collision Help...

Hi Andrew, thanks for your response, here is more of my code below:

local beginX local beginY local endX local endY local xDistance local yDistance function checkSwipeDirection() xDistance = math.abs(endX - beginX) yDistance = math.abs(endY - beginY) if xDistance \> yDistance then if beginX \> endX and ceilingCollisionBoolean == false then transition.to(mover, {time=200, x=(mover.x-80), y=mover.y}) else transition.to(mover, {time=200, x=(mover.x+80), y=mover.y}) end else if beginY \> endY then transition.to(mover, {time=200, x=mover.x, y=(mover.y-80)}) else transition.to(mover, {time=200, x=mover.x, y=(mover.y+80)}) end end end function swipe(event) if event.phase == "began" then beginX = event.x beginY = event.y end if event.phase == "ended" then endX = event.x endY = event.y checkSwipeDirection() end end Runtime:addEventListener("touch", swipe) local ceilingCollisionBoolean local function moverCollision(event) if (event.phase == "began") then if event.object1.name == "ceiling" and event.object2.name == "mover" then ceilingCollisionBoolean = true print("collision occurred") elseif event.object1.name == "mover" and event.object2.name == "ceiling" then ceilingCollisionBoolean = true print("collision occurred") else ceilingCollisionBoolean = false end end end Runtime:addEventListener ("collision", moverCollision)

Please let me know if you have any thoughts thanks!

OK, that helps.  It would also be somewhat helpful if you described a bit more in words exactly the behavior you’re hoping to achieve, and what’s happening instead.

One quick thing I notice is that you in your checkSwipeDirection function, you use the ceilingCollisionBoolean when considering the x direction and movement.  But the x direction is horizontal, whereas your ceiling (I imagine) is on the top and should be limiting the vertical movement, which is the y direction.

  • Andrew

Essentially, I am trying to have an object move on a grid and on a swipe move 80px the way the screen is swiped. However, I am trying to add walls that stop the mover but using physics does not seem to stop the transition.to statement, so I am trying to create a function that detects when the object is colliding with a certain wall and then not allow the object to transition a certain way when the object is colliding with a certain wall. I hope this helps you understand and I changed the ceilingCollisionBoolean to govern the moving up statement. Thanks again!