Interesting article about gravity in games

General discussion about LÖVE, Lua, game development, puns, and unicorns.

Interesting article about gravity in games

Postby kikito on Tue Dec 18, 2012 8:31 am

Check it out if you are into that sort of thing:

http://www.niksula.hut.fi/~hkankaan/Hom ... avity.html
When I write def I mean function.
User avatar
kikito
Inner party member
 
Posts: 2478
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain

Re: Interesting article about gravity in games

Postby substitute541 on Tue Dec 18, 2012 9:27 am

Very interesting...
Twitter: http://www.twitter.com/PhoenixCEnero
Randomly creating projects and abandoning them after a month.
User avatar
substitute541
Party member
 
Posts: 434
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines

Re: Interesting article about gravity in games

Postby Boolsheet on Tue Dec 18, 2012 10:00 am

One could call that a second-order approximation, right?

Accelerating physics are no longer approximation!

That's a dangerous statement. It's always an approximation unless we can throw an enormous amount of computation at it. Even then, we probably have to settle for a "accurate enough". :P
Shallow indentations.
User avatar
Boolsheet
Inner party member
 
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Interesting article about gravity in games

Postby kikito on Tue Dec 18, 2012 10:57 am

Boolsheet wrote:
Accelerating physics are no longer approximation!

That's a dangerous statement.


Using the term "physics" is wrong there, of course. I think he means that the implementation is aligned with the conventional model used in games, while the "conventional" implementation, is more like an aproximation of that model. The "real" physical phenomenon is not even considered.
When I write def I mean function.
User avatar
kikito
Inner party member
 
Posts: 2478
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain

Re: Interesting article about gravity in games

Postby Jasoco on Tue Dec 18, 2012 5:07 pm

This actually explains the problem I had way back when I was creating my first sidescroller prototype and when my framerate would suddenly drop (For instance when my desktop picture would fade from one to another, Löve would have a tendency to drop its FPS to a very low amount) my player jumping would suddenly not be as perfect as it would with a constantly high framerate.
Love.filesystem.enumerate is a very serious problem in our lives, we need to understand the problem about Love.filesystem.enumerate. We can discuss how to make it work, to avoid the inconvenience of our lives. -- Some Spambot
User avatar
Jasoco
Inner party member
 
Posts: 2721
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA

Re: Interesting article about gravity in games

Postby Inny on Tue Dec 18, 2012 8:01 pm

Interesting solution for the problem. I'm of the mindset that any degree of complex game physics should probably done quantized, i.e. that you do the world logic updates at a fixed framerate independent of the video framerate, and things like Box2d make this recommendation also (make a fixed timestep). But for simpler logic, I like this a lot, it has a strange elegance in its simplicity. Thanks for showing us this.
User avatar
Inny
Party member
 
Posts: 491
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Interesting article about gravity in games

Postby dreadkillz on Tue Dec 18, 2012 8:42 pm

Ah classical mechanics! Just a warning to readers, this method only works if the acceleration is constant. If your acceleration is a function of position or velocity, then you will need an approximate method or solve for the differential equation in another way.
User avatar
dreadkillz
Party member
 
Posts: 223
Joined: Sun Mar 04, 2012 2:04 pm
Location: USA

Re: Interesting article about gravity in games

Postby substitute541 on Wed Dec 19, 2012 3:22 am

Just a note. It is still inaccurate for VERY low FPS. Just look at the new algorithm's picture, the 3 FPS example didn't even reach the correct position.
Twitter: http://www.twitter.com/PhoenixCEnero
Randomly creating projects and abandoning them after a month.
User avatar
substitute541
Party member
 
Posts: 434
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines

Re: Interesting article about gravity in games

Postby Jasoco on Wed Dec 19, 2012 3:59 am

If you're getting 3FPS in a game, you probably won't enjoy playing that game anyway.
Love.filesystem.enumerate is a very serious problem in our lives, we need to understand the problem about Love.filesystem.enumerate. We can discuss how to make it work, to avoid the inconvenience of our lives. -- Some Spambot
User avatar
Jasoco
Inner party member
 
Posts: 2721
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA

Re: Interesting article about gravity in games

Postby Wojak on Wed Dec 19, 2012 11:47 am

I got something little different, but it seams to work just fine with low FPS:
Code: Select all
bullet.time = bullet.time + dt
bullet.speedy = bullet.speedy0 – 100*gravity*bullet.time
bullet.y = bullet.y  - bullet.speedy*dt


bullet.speedy0 is a initial velocity and it's constant for most of the time.
When an object interacts with something bullet.speedy0 is recalculated and bullet.time is reset

Exemplar in the attachment (left click outside the blue ball to create new object, you can move the blue ball with arrow keys, first blue number is FPS, the other is the object counter)
Attachments
gravity.love
(1.13 KiB) Downloaded 70 times
Wojak
Party member
 
Posts: 107
Joined: Tue Jan 24, 2012 7:15 pm

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest