Page 1 of 1

Gravity problems

Posted: Sun May 03, 2009 11:53 am
by eliasaif
Hi!
I'm pretty new to LOVE and I have a problem with the gravity in the physics engine. The game I'm developing is a platform game.

The gravity doesn't seem to work properly in the game. When an object is falling, the falling speed only accelerates to a certain point. Also, the falling speed decreases when moving to the left or right. Any ideas why this happens?
/Elias

Re: Gravity problems

Posted: Sun May 03, 2009 12:27 pm
by Robin
There seem to be even more problems. LÖVE can't load the first image file ("images/grass2.png", and it exists), but does load the other files without complaining. When loaded, I get a mostly black screen except for two cloud images. Sorry, but I'm afraid I can't help you out here.

Re: Gravity problems

Posted: Sun May 03, 2009 12:42 pm
by bartbes
Known, and posted a lot, let me give you the first forum post about this: http://love2d.org/forum/viewtopic.php?f=3&t=223

EDIT: I wanted to add, you might want to take a look at CAMERA to solve this: http://love2d.org/wiki/index.php?title=CAMERA

Re: Gravity problems

Posted: Sun May 03, 2009 1:35 pm
by eliasaif
Thanks for your answer bartbes! But how does CAMERA affect the gravity? I know it has something with units and pixels to do, but I don't really understand how.. Can anyone explain this to me?

Re: Gravity problems

Posted: Sun May 03, 2009 1:48 pm
by bartbes
Box2D is not supposed to work with pixels, but with some undefined units.
Pixels are too small for Box2D as it thinks the smallest things (in pixels) are huge objects.
That's why Box2D limits movement at 200 units/second. Which is a lot, if you consider a normal human-size object should be ~2 units (possibly even less).

CAMERA auto-scales, so you can use your own unit for graphics as well.
Example, you have a human-size object of 2 units, you set up CAMERA to scale that to... say 100 pixels.
You draw everything normal, like you would with pixels, but instead you now use the number 2, which is then compatible with the physics engine.
polygonShape:getPoints() now returns the same units as you use for drawing, so Box2D has the units it wants, and you don't have to manually convert every time you draw.

Hope this explains enough...

Re: Gravity problems

Posted: Sun May 03, 2009 11:19 pm
by lejeunerenard
Ive had this problem too in the past and instead of opting to using Camera for scaling I wrote my own scaling methods which you can find here: http://love2d.org/forum/viewtopic.php?f=4&t=666#p6329. That whole post may be helpful.

Also if you are looking to make a physics based platforming game then you might want to look into my physics platform game framework/engine found here: http://love2d.org/forum/viewtopic.php?f=5&t=690 though I will admit that it might just confuse you. It was written with the ENVY framework and my code is extremely messy, but if you want to bumble around my chaos for code you are welcome. Eventually I plan on cleaning it up and making it more user friendly.

Re: Gravity problems

Posted: Mon May 04, 2009 6:34 pm
by eliasaif
Thanks! Works fine now! :)

Re: Gravity problems

Posted: Thu May 07, 2009 9:40 pm
by qubodup
Looks really cute.

I wasn't able to get the ball up though.

I recommend to never default-fullscreen. the game froze and I had to kill it and restart X. That pissed me off.

Re: Gravity problems

Posted: Mon May 11, 2009 5:54 am
by eliasaif
Oh, sorry. Forgot to change it..