1

I am trying to make it so when my red circle touches the white circle it cannot move past it. I have tried basic if statements but it does not work. Anyway here is the code...

win = love.window.setMode(600, 600)
Xpos = 300
TX = 50

function love.draw()
    love.graphics.setColor(1, 1, 1)
    love.graphics.circle("fill", Xpos, 200, 25)
    love.graphics.setColor(1, 0, 0)
    love.graphics.circle("fill", TX, 200, 60)

    if Xpos == TX then 
        Xpos = Xpos + 0.1
    end

    if TX >= Xpos then
        TX = TX - 35
    end

    if love.keyboard.isDown("right") then
        TX = TX + 5
    end
end
mDeram
  • 69
  • 1
  • 9
  • Does this answer your question? [love2D cannot figure out how to make basic collision with two circles does not give error](https://stackoverflow.com/questions/63853626/love2d-cannot-figure-out-how-to-make-basic-collision-with-two-circles-does-not-g) – Sam Sep 11 '20 at 21:49
  • What behaviour are you getting? – Sherlock Holmes Jan 13 '21 at 06:24

1 Answers1

0

Try the basic AABB collision detector:

function Something:collides(target)
    if self.x > target.x + target.width or target.x > self.x + self.width then
        return false
    end
    
    if self.y > target.y + target.height or target.y > self.y + self.height then
        return false
    end
end