Page 1 of 1

Unable to set physics body mass

Posted: Fri Oct 29, 2021 11:38 pm
by Voltaia
The size of my physics body is 86x68 pixels, but for some reason when I set the center of mass with Body:setMassData() I get some really weird problems. If I try to set x larger than 14, I get an error. If I try to set y larger than 5, I get an error.

Why would this be happening??? I'm using a rectangular shape set to dynamic. I believe it's a bug.

The error I get is: Box2D assertion failed: m_l > 0.0f

Re: Unable to set physics body mass

Posted: Sat Oct 30, 2021 1:36 am
by pgimeno
You haven't provided nearly enough information, but the problem is probably that the moment of inertia does not allow for that centre.

I can't reproduce the problem with this:

Code: Select all

local world = love.physics.newWorld(0, 0, false)
local shape = love.physics.newRectangleShape(86, 68)
local body = love.physics.newBody(world, 400, 300, "dynamic")
local fixture = love.physics.newFixture(body, shape)

-- Change only the centre without altering the mass or the moment of inertia
local x, y, mass, moi = body:getMassData()
body:setMassData(15, 0, mass, moi)
But it can be reproduced by setting a low moment of inertia.

Doesn't sound like a bug, but a physics engine limitation.

Re: Unable to set physics body mass

Posted: Mon Nov 01, 2021 7:20 pm
by Voltaia
Wait - why does altering the mass restrict where I can set my center of mass? I haven't altered the inertia at all, but I don't get the errors when I set my mass to 1.