Gravity problems

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
User avatar
eliasaif
Prole
Posts: 25
Joined: Sat May 02, 2009 4:04 pm
Location: Sweden

Gravity problems

Post 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
Attachments
thegame.love
(246.64 KiB) Downloaded 211 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Gravity problems

Post 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.
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Gravity problems

Post 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
User avatar
eliasaif
Prole
Posts: 25
Joined: Sat May 02, 2009 4:04 pm
Location: Sweden

Re: Gravity problems

Post 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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Gravity problems

Post 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...
lejeunerenard
Prole
Posts: 11
Joined: Mon Apr 13, 2009 7:33 pm
Contact:

Re: Gravity problems

Post 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.
User avatar
eliasaif
Prole
Posts: 25
Joined: Sat May 02, 2009 4:04 pm
Location: Sweden

Re: Gravity problems

Post by eliasaif »

Thanks! Works fine now! :)
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: Gravity problems

Post 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.
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
eliasaif
Prole
Posts: 25
Joined: Sat May 02, 2009 4:04 pm
Location: Sweden

Re: Gravity problems

Post by eliasaif »

Oh, sorry. Forgot to change it..
Post Reply

Who is online

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