Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (292)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Variable step timing - Good or bad?  (Read 1773 times)
0 Members and 1 Guest are viewing this topic.
Offline mrekim

Junior Newbie





« Posted 2012-02-19 23:32:44 »

I've read the Game-Loops Thread (http://www.java-gaming.org/topics/game-loops/24220/view.html) today and I'm curious about the var step timing regarding collision detection.
Let's say I've got a pretty decent PC, capping the fps at 60 fps and I move a primitive like this:
1  
2  
x = x+0.1f*delta;
rectangle.setX(x);


Now this should run fine on most machines and it will stutter if I cap the FPS at 5 Fps.
When I now test pixel perfect collision with the 5 FPS Cap it is not possible to get the same accuracy as I get with more FPS.
Are there any tricks to solve this? Or do I need fixed step timing?

Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #1 - Posted 2012-02-20 00:34:40 »

First question is: why do you feel the need to cap at 5FPS?

Setting the game loop at 60FPS should be sufficient enough for most collision detection.

However if you still feel the need to check for those "in-between" areas, you could just create a rectangle that encompasses that area and check for collision that way.

Offline ReBirth
« Reply #2 - Posted 2012-02-20 03:41:02 »

Actually collision on low fps should work, if you store the x and y in double.

Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Beamery

Senior Newbie


Medals: 1



« Reply #3 - Posted 2012-02-20 05:18:17 »

The lack of accuracy is likely just due the the fact that there is more time between updates.  More time between updates means more entity movement between updates and the potential for an entity to move into and then out of collision with another entity before the game is updated. Also puzzled as to why you would want to cap the FPS at 5...
Online Roquen

JGO Ninja


Medals: 66



« Reply #4 - Posted 2012-02-20 08:38:24 »

Variable time steps leads to non-deterministic simulations.  Personally I consider that to be undesirable.  Using doubles doesn't (really) solve anything.
Offline mrekim

Junior Newbie





« Reply #5 - Posted 2012-02-20 09:47:42 »

I know, that no one would cap at 5 FPS - I just did for testing the collision.
Thanks for your answers yet - another possibility in for me was to calculate the optimal time like 1000ms/60 for 60FPS = ~16.
Now I sum up the delta times for every update and do the update when the sum >= 16.
But I feel like wasting resources as this would render duplicate frames without changing anything.

I will try to implement fixed step timing. Anyone ever did this within the Slick Framework?
Offline ReBirth
« Reply #6 - Posted 2012-02-21 04:58:09 »

Just add sleep...?

Offline mrekim

Junior Newbie





« Reply #7 - Posted 2012-02-21 09:54:31 »

well... Cheesy Actualy I also want to interpolate the drawings.
Online Roquen

JGO Ninja


Medals: 66



« Reply #8 - Posted 2012-02-21 11:11:14 »

If you want to keep it simple.  Just render and update the simulation at 60Hz and if you slow down...so be  it.
Offline Beamery

Senior Newbie


Medals: 1



« Reply #9 - Posted 2012-02-21 16:50:27 »

If you want to keep it simple.  Just render and update the simulation at 60Hz and if you slow down...so be  it.

This is what I've done with my game loop and it seems to work fine so far.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal
« League of Dukes »

JGO Kernel


Medals: 39
Projects: 12


Game Engineer


« Reply #10 - Posted 2012-02-23 20:42:29 »

In general it's probably a good idea to add in sweeping collision or something like that, because you will have the same problem at any FPS if you have very fast objects.

See my work:
OTC Software
Online Roquen

JGO Ninja


Medals: 66



« Reply #11 - Posted 2012-02-24 10:01:03 »

On the whole, it'd suggest just using a pre-exisiting physic library.  Building one from scratch is alot of work.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (67 views)
2013-05-17 21:29:12

alaslipknot (76 views)
2013-05-16 21:24:48

gouessej (109 views)
2013-05-16 00:53:38

gouessej (104 views)
2013-05-16 00:17:58

theagentd (115 views)
2013-05-15 15:01:13

theagentd (104 views)
2013-05-15 15:00:54

StreetDoggy (149 views)
2013-05-14 15:56:26

kutucuk (172 views)
2013-05-12 17:10:36

kutucuk (170 views)
2013-05-12 15:36:09

UnluckyDevil (179 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.246 seconds with 21 queries.