Hello,
i have a problem with the collision detection when the object is moving too fast
require("physics") physics.start() physics.setDrawMode("normal") physics.setGravity(0,0) local wall local player local groupLine = display.newGroup() function onTouch( event ) local target = event.target local phase = event.phase if event.phase == "began" then target.x0 = event.x - target.x target.y0 = event.y - target.y target.xStart = target.x target.yStart = target.y elseif event.phase == "moved" then local line = display.newLine( target.x, target.y, event.x, event.y) line:setStrokeColor( 1, 1, 1 ) line.strokeWidth = 1 physics.addBody(line, "kinematic", { bounce = 0, density=0 ,friction=10}) line.myname ="player" line.isSensor = true groupLine:insert(line) target.x = event.x - target.x0 target.y = event.y - target.y0 elseif event.phase=="ended"then target.x, target.y = event.x, event.y end return true end function onCollision( event ) if(event.other.myname=="player")then wall:setFillColor(1,0,0) end return true end player = display.newRect( 100, 100, 20, 20 ) player.myname ="player" physics.addBody(player, "dynamic", { bounce = 0, density=1 ,friction=1}) player:addEventListener( "touch", onTouch ) player.isBullet=true wall = display.newRect( 200, 100, 5, 100 ) wall.myname ="wall" wall:setFillColor(0,1,0) physics.addBody(wall, "static", { bounce = 0, density=1 ,friction=1}) wall:addEventListener( "collision", onCollision ) function resetFunction() for i=groupLine.numChildren,1,-1 do display.remove(groupLine[i]) end wall:setFillColor(0,1,0) return true end local reset = display.newRect( 100, 200, 20, 20 ) reset:addEventListener( "tap", resetFunction )
i tried to use the lines to detect collision better but it dont work.