Body:setAngularVelocity(0) isnt doing what I expected

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
zell2002
Citizen
Posts: 75
Joined: Sun Feb 23, 2014 9:22 pm

Body:setAngularVelocity(0) isnt doing what I expected

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

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

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

Who is online

Users browsing this forum: Ahrefs [Bot] and 41 guests