How does linear velocity work ?

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
roschan
Prole
Posts: 2
Joined: Mon May 23, 2016 6:17 pm

How does linear velocity work ?

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

Re: How does linear velocity work ?

Post 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
roschan
Prole
Posts: 2
Joined: Mon May 23, 2016 6:17 pm

Re: How does linear velocity work ?

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

Re: How does linear velocity work ?

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

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 6 guests