If you make the two “paddles” touch each other, the first time they touch it works, but every subsequent time after that hey simply phase through each other.
displayMode( FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
p1=physics.body(CIRCLE,30)
p1.position = vec2(50,HEIGHT/2)
p1.name = "paddle1"
p1.gravityScale = 0
p1.type = DYNAMIC
p1.draw = function()
pushStyle()
noStroke()
fill(255)
ellipse(p1.x,p1.y,p1.radius*2)
popStyle()
end
p2=physics.body(CIRCLE,30)
p2.position = vec2(WIDTH-50,HEIGHT/2)
p2.name = "paddle1"
p2.gravityScale = 0
p2.type = DYNAMIC
p2.draw = function()
pushStyle()
noStroke()
fill(255)
ellipse(p2.x,p2.y,p2.radius*2)
popStyle()
end
end
function draw()
background(0)
p1:draw()
p2:draw()
end
function touched(t)
if t.state == BEGAN and p1.position:dist(vec2(t.x,t.y))<25 then
touch1 = t
elseif t.state == BEGAN and p2.position:dist(vec2(t.x,t.y))<25 then
touch2 = t
end
if t.state == MOVING and touch1 and t.id == touch1.id then
p1.position = vec2(t.x,t.y)
if t.x > WIDTH/2 then
p1.position.x = WIDTH/2
end
elseif t.state == MOVING and touch2 and t.id == touch2.id then
p2.position = vec2(t.x,t.y)
if t.x < WIDTH/2 then
p2.position.x = WIDTH/2
end
end
end