Search code examples
luacollisionlove2d

Why does this collision code not work? (love2d)


function love.collide ()
  if x < 0 then
    x = 0
  end

  if x < love.graphics.getWidth () - Dolphin:getWidth () then
  x = love.graphics.getWidth () - Dolphin:getWidth ()
  end

end

I'm trying to make an x coordinate collision and I have already defined x previously. There is no error but the collision fails to work.


Solution

  • I think you mean x > love.graphic.getWidth() - Dolphin:getWidth(). Because otherwise your Dolphin should always be stuck at the right-hand boundary.