I am trying to use the contact function to determine whether two objects have collided or not. When I run my program it prints “hello” regardless of whether the two objects are touching or not. Here is the code I have produced so far. I am new to Codea so if its really simple then I apologise.
function setup()
ball = physics.body(CIRCLE, 50)
ball.x = 0
ball.y = 0
ball.restitution = .5
ball.info = "ball"
enemyBall = physics.body(CIRCLE, 50)
enemyBall.x = 0
enemyBall.y = 0
enemyBall.restitution = .5
enemyBall.info = "enemyBall"
function collide( contact )
if contact.state == BEGAN then
if contact.bodyA.info == "ball" and contact.bodyB.info == "enemyBall"
or contact.bodyA.info == "enemyBall" and contact.bodyB.info == "ball" then
print("hello")
end
end
function draw()
physics.gravity(Gravity)
fill(27, 255, 0, 255)
ellipse(x, playerImagePosition.y, ball.radius*1.5)
physics.gravity(Gravity)
fill(0, 255, 29, 255)
ellipse(enemy1Position.x, 500, enemyBall.radius*1.5)