Page 1 of 1

Body:setAngularVelocity(0) isnt doing what I expected

Posted: Sun Feb 11, 2018 5:16 pm
by zell2002
When using Body:setAngularVelocity(n) it starts my Body rotating.
I was expecting passing 0 would cause it to stop rotating ?
Has anyone else experienced this? or am I using this func wrong

Re: Body:setAngularVelocity(0) isnt doing what I expected

Posted: Sun Feb 11, 2018 6:40 pm
by pgimeno
Works for me:

Code: Select all

local world = love.physics.newWorld(0, 0, false)
local body = love.physics.newBody(world, 0, 0, "dynamic")
local shape = love.physics.newRectangleShape(200, 150)
love.physics.newFixture(body, shape)


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

function love.keypressed(k)
  if k == "a" then
    body:setAngularVelocity(-math.pi)
  end
  if k == "s" then
    body:setAngularVelocity(0)
  end
  if k == "d" then
    body:setAngularVelocity(math.pi)
  end
  if k == "escape" then love.event.quit() end
end

function love.draw()
  love.graphics.translate(400.5,300.5)
  love.graphics.polygon("line", body:getWorldPoints(shape:getPoints()))
end
No idea what you're doing, so I can't say more.