Page 1 of 1

How does linear velocity work ?

Posted: Sun May 29, 2016 11:19 pm
by roschan
Hello, i'm trying to use this https://love2d.org/wiki/Body:setLinearVelocity and this https://love2d.org/wiki/Body:getLinearVelocity but i don't understand how they work. The "getLinearVelocity" function always returns me zeros.
For example, this love.update function :

Code: Select all

function love.update(dt)
	body:setLinearVelocity(800, 800)
	world:update(dt)
	print(body:getLinearVelocity())
end
My terminal is full of ... zeros :huh: This seems not logic...
But I'm new here, I don't seriously know how to do something with LÖVE so my problem may be very stupid... ^^

Re: How does linear velocity work ?

Posted: Mon May 30, 2016 12:09 am
by pgimeno
Works for me. Can you post a complete example?

Edit: Here's my test:

Code: Select all

local world, body, shape, fixture

function love.load()
  world = love.physics.newWorld(0, 0)
  body = love.physics.newBody(world, 400, 300, "dynamic")
  shape = love.physics.newCircleShape(5)
  fixture = love.physics.newFixture(body, shape)
end

function love.update(dt)
   body:setLinearVelocity(800, 800)
   world:update(dt)
   print(body:getLinearVelocity())
end

Re: How does linear velocity work ?

Posted: Mon May 30, 2016 12:00 pm
by roschan
Ok my bad. As i guessed, it was a very very stupid error : I didn't notice I was supposed to use quotes in the declaration of the new body...
Now it works for me to, thank ^^

Re: How does linear velocity work ?

Posted: Mon May 30, 2016 10:53 pm
by pgimeno
Sure. Notice how the problem wasn't in the snippet you posted. That's why it's important to provide a full example demonstrating a problem if you're asking for help. Doing so the next time you ask will help us help you.