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: 56
Joined: Sun Feb 23, 2014 9:22 pm

Body:setAngularVelocity(0) isnt doing what I expected

Post by zell2002 » Sun Feb 11, 2018 5:16 pm

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: 1531
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno » Sun Feb 11, 2018 6:40 pm

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.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests