Below is a bit of code that creates a circle, a static box and a rotating (kinematic box).
When the circle falls down it falls on the static box and goes to sleep - however, collision with the kinematic body doesn't wake it up so the collision goes totally unnoticed. Is that supposed to be like that?
If I set the circle to never go to sleep it works as expected but that's not optimal - a sleeping object is supposed to be woken up at collision?
I tried making the box dynamic instead of kinematic but it makes no difference (at least, if I set rotation explicitly, I'd rather not use forces myself, that's what kinematic bodies are for after all).
Anyone have an explanation, or solution (outside of disabling sleep on objects or, heaven forbid, the world?)
Thanks,
Kaj
Code: Select all
love.physics.setMeter(64)
world = love.physics.newWorld( 0 * 64, 0.981 * 64, true )
-- create a body
local body = love.physics.newBody(world, 100, 100, "dynamic")
local sphere = love.physics.newCircleShape( 30 )
local fixture = love.physics.newFixture(body, sphere, 100)
--body:setSleepingAllowed(false) -- >> putting this line in makes it work
-- create a body for the ground - rectangle
local ground = love.physics.newBody(world, 90, 400, "kinematic")
local rect = love.physics.newRectangleShape( 800,100 )
local fixture = love.physics.newFixture(ground, rect, 100)
-- chainshape
--local polybody = love.physics.newBody(world, 90, 300, "static")
--local poly = love.physics.newChainShape( false, -100,0, 100, 0, 100, 100 )
--local fixture = love.physics.newFixture(polybody, poly, 100)
-- chainshape
local polybody = love.physics.newBody(world, 90, 300, "static")
--local poly = love.physics.newEdgeShape( -100,0, 100, 0 )
local poly = love.physics.newRectangleShape( 200,100 )
local fixture = love.physics.newFixture(polybody, poly, 100)
function love.update(dt)
ground:setAngle(ground:getAngle()+0.1*dt)
world:update(dt)
end
function DrawPhysicsShape(body,shape)
love.graphics.push()
love.graphics.translate(body:getPosition())
love.graphics.rotate(body:getAngle())
local type = shape:getType()
if type == "circle" then
love.graphics.circle("line",0,0,shape:getRadius())
elseif type == "polygon" then
love.graphics.polygon("line",shape:getPoints())
elseif type == "chain" then
love.graphics.line(shape:getPoints())
end
love.graphics.pop()
end
function DrawPhysicsBody(body)
if body:getType() == "static" then
love.graphics.setColor(255,0,0,255)
else
love.graphics.setColor(0,255,0,255)
end
local fixtures = body:getFixtureList()
for i=1,#fixtures do
local fixture = fixtures[i]
local body = fixture:getBody()
local shape = fixture:getShape()
DrawPhysicsShape(body,shape)
end
end
function DrawPhysicsWorld(world )
local r,g,b,a = love.graphics.getColor()
local bodies = world:getBodyList()
for i=1,#bodies do
DrawPhysicsBody(bodies[i])
end
love.graphics.setColor(r,g,b,a)
end
function love.draw()
DrawPhysicsWorld(world)
end