I faced with a problem of physics (Box2d) world recreation. I mean that physics works different when I create -> destroy -> create the same world again.
I have made simple example here. It shows the speed of failing object:
Code: Select all
total_time = 0
function recreate_world()
-- If physics world exists destroy it!
if world then
world:destroy()
-- Just to be sure
world = nil
collectgarbage()
end
-- Create physics world
world = love.physics.newWorld(0, 10, true)
love.physics.setMeter(64)
-- Create object
player = {}
player.body = love.physics.newBody(world, 0, 0 , "dynamic")
player.shape = love.physics.newCircleShape(10)
player.fixture = love.physics.newFixture(player.body, player.shape, 10)
end
function love.load()
recreate_world()
end
function love.update(dt)
total_time = total_time + dt
world:update(dt)
-- Recreate physics world each 5 seconds
if total_time >= 5 then
player_speed = math.abs(player.body:getY() / total_time)
print(player_speed .. " pixels per second")
recreate_world()
total_time = 0
end
end
Code: Select all
53.349362755674 pixels per second
25.007504284116 pixels per second
25.010326393036 pixels per second
25.009385496829 pixels per second
25.012307404012 pixels per second
25.00637001891 pixels per second
25.01000082252 pixels per second
What am I doing wrong or it's known bug?