Page 1 of 1

Strange collision on rectangles using default physics

Posted: Fri Sep 14, 2018 1:45 am
by breeblo
I'm attempting to use the default physics system with rectangular, non-rotating shapes. I can't find any explanation for my problem after searching the wiki and forums for around 20 minutes. I'm attempting to use rectangles as collision boxes for all entities in the game. However, I immediately noticed weird behavior when stuff collided. Bodies seem to behave as though they have rounded corners, with rectangles rolling off of each other when their corners collide, despite having fixed rotation. Sometimes, bodies will also bounce despite having 0 restitution, which I thought would remove all elasticity/bounciness from a fixture.

I threw something quick and extremely crude together in order to test the issue:

Code: Select all

phys=love.physics.newWorld(0,500)
love.physics.setMeter(8)

function love.load()
  ents={}
  local ent={}
  ent.body=love.physics.newBody(phys,0,0,"dynamic")
  ent.body:isFixedRotation(true)
  ent.body:setPosition(60,0)
  ent.shape=love.physics.newRectangleShape(16,16)
  ent.fixture=love.physics.newFixture(ent.body,ent.shape)
  ent.fixture:setFriction(0)
  ent.fixture:setRestitution(0)
  table.insert(ents,ent)
  local ent={}
  ent.body=love.physics.newBody(phys,0,0,"static")
  ent.body:isFixedRotation(true)
  ent.body:setPosition(50,100)
  ent.shape=love.physics.newRectangleShape(16,16)
  ent.fixture=love.physics.newFixture(ent.body,ent.shape)
  ent.fixture:setFriction(0)
  ent.fixture:setRestitution(0)
  table.insert(ents,ent)
end

function love.update(dt)
  phys:update(dt)
end

function love.draw()
  for i,v in pairs(ents) do
    local px,py=v.body:getPosition()
    local x1,y1,x2,y2,x3,y3,x4,y4=v.shape:getPoints()
    love.graphics.polygon("fill",{x1+px,y1+py,x2+px,y2+py,x3+px,y3+py,x4+px,y4+py})
  end
end
This reproduces my issue perfectly, even after cutting out everything else. Is there something I'm missing? Am I doing something really obvious and stupid?

Re: Strange collision on rectangles using default physics

Posted: Sun Sep 16, 2018 9:08 am
by JoshGrams
You want setFixedRotation instead of isFixedRotation.