I hunk it has something to do with how I’m resetting the inAir variable (collide function)
-- 2D Game
function setup()
physics.continuous=true
diam = 60
w1 = physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
w2 = physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
w3 = physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
w4 = physics.body(EDGE, vec2(0, HEIGHT), vec2(WIDTH, HEIGHT))
ball = physics.body(CIRCLE, 30)
ball.gravityScale = 1
ball.restitution = .8
ball.x = 50
ball.y = 50
direction = "none"
up = false
inAir = false
end
function draw()
local y = 0
if up == true then
up = false
y = 5000
inAir = true
end
if direction == "LEFT" then
ball.linearVelocity = vec2(-75, y)
elseif direction == "RIGHT" then
ball.linearVelocity = vec2(75, y)
end
--Set up color stuff
background(0, 0, 0)
--Set up ball stuff
fill(255,0,0)
strokeWidth(0)
--Draw the ball using x,y position of physics object
ellipse(ball.x,ball.y,diam)
--Set up wall stuff
stroke(255, 255, 255, 255)
strokeWidth(2)
--Draw walls
line(0, 0, WIDTH, 0)
line(0, 0, 0, HEIGHT)
line(WIDTH, 0, WIDTH, HEIGHT)
line(0, HEIGHT, WIDTH, HEIGHT)
end
function touched(t)
if t.state == BEGAN then
if t.x < WIDTH/2 then
direction = "LEFT"
else
direction = "RIGHT"
end
if t.y > HEIGHT/2 and inAir == false then
up = true
end
else
direction = "none"
end
end
function collide(contact)
if contact == BEGAN and contact.bodyA == ball and contact.bodyB == w1 then
inAir = false
end
end
See latest post for new question.