Unable to set physics body mass

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Voltaia
Prole
Posts: 3
Joined: Fri Oct 29, 2021 11:30 pm

Unable to set physics body mass

Post 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
User avatar
pgimeno
Party member
Posts: 3285
Joined: Sun Oct 18, 2015 2:58 pm

Re: Unable to set physics body mass

Post 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.
Voltaia
Prole
Posts: 3
Joined: Fri Oct 29, 2021 11:30 pm

Re: Unable to set physics body mass

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 105 guests