# Collisions Between Circles

I have 2 Circle Bodies and I am trying to detect a collision between them, however it always detects a collision. Does anyone know why this would be?

Here is my code:

``````  function setup()

end

function draw()

local circle = physics.body(CIRCLE, 50)
-- enable smooth motion
circle.interpolate = true
circle.x = 100
circle.y = 200
circle.restitution = 0.25
circle.sleepingAllowed = false

local circle1 = physics.body(CIRCLE, 50)
-- enable smooth motion
circle1.interpolate = true
circle1.x = 800
circle1.y = 900
circle1.restitution = 0.25
circle1.sleepingAllowed = false

end

function collide(contact)

if contact.state == BEGAN then
print("hit")
end
end
``````
``````
supportedOrientations(PORTRAIT_ANY)

function setup()
circle = physics.body(CIRCLE, 50)
-- enable smooth motion
circle.interpolate = true
circle.x = 300
circle.y = 100
circle.sleepingAllowed = false
circle.type=STATIC

circle1 = physics.body(CIRCLE, 50)
-- enable smooth motion
circle1.interpolate = true
circle1.x = 300
circle1.y = 900
circle1.restitution = 0.8
circle1.sleepingAllowed = false
end

function draw()
background(40,40,50)
fill(255)
ellipse(circle.x,circle.y,100)
ellipse(circle1.x,circle1.y,100)
end

function collide(contact)
if contact.state == BEGAN then
print("hit")
end
end

``````

@austinmccoy Not sure, but maybe it’s because you created the bodies in the draw function, creating them 60 times per second. This would cause a LOT of bodies to be in the same place, ‘colliding’. It should be fixed if you create the bodies in the setup function. Also, if you are wondering why they are not visible, you need to create ellipses and draw them with the position of the physics bodies. I’ll get back to you with some code.
EDIT : I see @dave1707 beat me to it. Simultaneous posts!

@austinmccoy by putting the object definition in the draw, you create new ones at the same position every 16ms, so they hit each other!
Also dont make them local, or they will get quickly destroyed

Thanks for the tips!