How do I make the ball hit the 2 rectangles whenever the ball hits one of them it just goes through it.
displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT)
function setup()
stroke(255, 0, 0, 255)
strokeWidth(2)
--walls
left = physics.body(EDGE, vec2(0, 0), vec2(0, HEIGHT))
right = physics.body(EDGE, vec2(WIDTH, 0), vec2(WIDTH, HEIGHT))
--ball
ball = physics.body(CIRCLE, 10)
ball.position = vec2(WIDTH/2, HEIGHT/2)
ball.linearVelocity = vec2(ball.x, ball.y)
ball.restitution = 1.01
ball.gravityScale = 0
ball.friction = 0
--rectangle
r = physics.body(POLYGON, vec2(WIDTH/2+40, HEIGHT/10), vec2(WIDTH/2-40, HEIGHT/10),
vec2(WIDTH/2-40, HEIGHT/10-5), vec2(WIDTH/2+40, HEIGHT/10-5))
r.position = vec2(WIDTH/2, HEIGHT/10)
r.linearVelocity = vec2(WIDTH/2, HEIGHT/10)
r.restitution = 1.1
r.gravityScale = 0
r.friction = 0
r.type = STATIC
--rectangle 2
r2 = physics.body(POLYGON, vec2(WIDTH/2+40, HEIGHT/1.1), vec2(WIDTH/2-40, HEIGHT/1.1),
vec2(WIDTH/2-40, HEIGHT/1.1-5), vec2(WIDTH/2+40, HEIGHT/1.1-5))
r2.position = vec2(WIDTH/2, HEIGHT/1.1)
r2.linearVelocity = vec2(WIDTH/2, HEIGHT/1.1)
r2.restitution = 1.1
r2.gravityScale = 0
r2.friction = 0
r2.type = STATIC
end
function draw()
background(0, 0, 0, 255)
ellipse(ball.x, ball.y, 20)
rect(r.x, HEIGHT/10, 80, 5)
rect(r2.x, HEIGHT/1.1, 80, 5)
end
function touched(t)
if math.abs(t.x-r.x)<200 and math.abs(t.y-r.y)<200 then
r.x=t.x
end
if math.abs(t.x-r2.x)<200 and math.abs(t.y-r2.y)<200 then
r2.x=t.x
end
end