Physics not simulating after altering tutorial program

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
Sami
Prole
Posts: 2
Joined: Sat Oct 08, 2011 4:21 pm

Physics not simulating after altering tutorial program

Post by Sami »

Just downloaded this wonderful library to prototype some ideas (may even use it for the actual thing!), and have hit a snag at the get-go. I'm experimenting with the physics module and have been altering the tutorial example. I have set the world to be 1 metre per pixel as it makes things far more intuitive. The largest dynamic body that gets created is 2 metres/pixels in radius.

The issue is... the ball just sits there in the air and isn't affected by gravity. I've set gravity to be the standard constant of 9.8, but changing that to be higher didn't make any difference. The entire program is listed below - any help is appreciated. There may be some quirks of Love/Box2D that I'm missing.

Thanks in advance :)

Code: Select all

function love.load ()

  world = love.physics.newWorld (0, 0, 650, 650)
  world:setGravity (0, 9.8)
  world:setMeter (1)

  objects = {}

  objects.ground = {}
  objects.ground.body = love.physics.newBody (world, 650/2, 625, 0, 0)
  objects.ground.shape = love.physics.newRectangleShape (objects.ground.body, 0, 0, 650, 50, 0)

  objects.ball = {}
  objects.ball.body = love.physics.newBody (world, 650/2, 650/2, 10, 0)
  objects.ball.shape = love.physics.newCircleShape (objects.ball.body, 0, 0, 2)

  love.graphics.setBackgroundColor (104, 136, 248)
  love.graphics.setMode (650, 650, false, true, 0)

end

function love.update (dt)

  world:update (dt)

end

function love.draw ()

  love.graphics.setColor (72, 160, 14)
  love.graphics.polygon ("fill", objects.ground.shape:getPoints ())

  love.graphics.setColor (193, 47, 14)
  love.graphics.circle ("fill", objects.ball.body:getX (), objects.ball.body:getY (), objects.ball.shape:getRadius (), 10)

end
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Physics not simulating after altering tutorial program

Post by bartbes »

The forces you are using are probably too small for objects of this size, you make a ball with a 2 meter radius of 10kg, that thing is going to be floaty as hell.
setMeter means you can just use your normal pixel input and it will automatically convert it to something more sane, (the default) 30 is generally pretty good, as that means a default window is 20 meters high.

If you, however, decide you do want to go do things this way (and Box2D explicitly tells you it is bad at simulating the movement of 'buildings'), you should either set higher weights or use setMassFromShapes.
Sami
Prole
Posts: 2
Joined: Sat Oct 08, 2011 4:21 pm

Re: Physics not simulating after altering tutorial program

Post by Sami »

A mass of 10kg with gravity of 9.8 acting on it should give it a weight of 98kg, i.e. that of a not exactly skinny human. Or am I mis-understanding how the gravity vector works?

edit: note that increasing the mass doesn't make the object move, nor does increasing the gravity, and nor does increasing them all.

edit 2: I'm aware Box2D says not to simulate large objects using this, which is why I am using small objects (4m is okay I take it?). Pixels aren't used as zooming in and out will be a part of the demo (when it gets past this stage), thus I want to keep the physics as decoupled from the current zoom level as possible.
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: Physics not simulating after altering tutorial program

Post by Ensayia »

Something to keep in mind if you are going to be working with Box2D, you may want to wait for the release of LOVE 0.8.0 in the near future. The API is getting completely overhauled and will no longer work with you current code.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Physics not simulating after altering tutorial program

Post by molul »

I'm having a similar issue as the OP. I don't quite understand how this physics module works. If I set the world's gravity to (0,9.8) and create a 15kg object, shouldn't I see it fall faster? I've also set 1 meter to 100px, which I think will fit in my future project. However, the ball's fall seems too slow to me. Could someone clear this up for me, please?

Thanks in advance :)
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Physics not simulating after altering tutorial program

Post by tentus »

I don't think that setGravity works how you think it does. Notice that in the original tutorial the y parameter is set to 700, which is heckuva different from 9.8. Yes, I know that gravity is 9.8 m/s^2, but I don't think that Box2D knows that.
Kurosuke needs beta testers
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Physics not simulating after altering tutorial program

Post by molul »

Perhaps gravity should be set to 980... I'm gonna look for Box2D gravity info.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 10 guests