Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (511)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
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  
  [LibGDX] Quite noticeable difference from delta-time  (Read 1295 times)
0 Members and 1 Guest are viewing this topic.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Posted 2013-11-08 13:11:06 »

So I was noticing quite a difference in the height my player jumps. I ran a little test and these were the results for the height of the jump:

Quote
1.5940161
1.5778124
1.7005899
1.5893874
1.5511405
1.5653098
1.7092321
1.5587344
1.5416918
1.9001534
1.5981796
1.6318316
1.4457531
1.6911268
1.7343032
1.6765044
1.5780396
1.765909
1.5760472
1.7882164
1.584327
1.5204363
1.6663692
1.3007994
1.5723152
1.5282481
1.4971516
1.7074564
1.54636
1.4520841
1.4209707
1.6715405
1.5326388
1.5750785
1.4799459
1.7682292
1.6133375
1.5507946
1.5831671

This uses a unit scale (1u = 32px) so the results sort of confused me. It has considerable differences nearly every single jump, but my jumping is based on delta time, which should give me very similar results every time.

Here is my jumping algorithm:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
if (jump && !jumping) {
   jumping = true;
   velocity.y = MAX_VELOCITY * deltaTime;
} else if (jumping) {
   position.y += velocity.y;
   velocity.y -= ACCELERATION * deltaTime;
   if (velocity.y < 0f) {
      velocity.y = 0;
      fall = true;
      jumping = false;
   }
}


I don't think I'm doing anything wrong. Could anyone suggest a possible cause of the differences?

Why are all OpenGL tutorials written in Brainf**k?
Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #1 - Posted 2013-11-08 13:14:00 »

Try this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
if (jump && !jumping) {
   jumping = true;
   velocity.y = MAX_VELOCITY;
} else if (jumping) {
   position.y += velocity.y * deltaTime;
   velocity.y -= ACCELERATION * deltaTime;
   if (velocity.y < 0f) {
      velocity.y = 0;
      fall = true;
      jumping = false;
   }
}

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #2 - Posted 2013-11-08 13:19:12 »

Try this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
if (jump && !jumping) {
   jumping = true;
   velocity.y = MAX_VELOCITY;
} else if (jumping) {
   position.y += velocity.y * deltaTime;
   velocity.y -= ACCELERATION * deltaTime;
   if (velocity.y < 0f) {
      velocity.y = 0;
      fall = true;
      jumping = false;
   }
}


Oh stupid me. I actually feel embarrassed to have posted this. :L

Why are all OpenGL tutorials written in Brainf**k?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #3 - Posted 2013-11-08 13:22:24 »

We've all been there my friend.

Offline Roquen
« Reply #4 - Posted 2013-11-08 13:48:27 »

I'd strongly suggest using fixed time-steps for simulation in future projects.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #5 - Posted 2013-11-08 14:03:21 »

I'd strongly suggest using fixed time-steps for simulation in future projects.

So I should just base it on 60fps for example? Should I also do that for moving left/right?

Why are all OpenGL tutorials written in Brainf**k?
Offline Roquen
« Reply #6 - Posted 2013-11-10 13:49:06 »

If you're not too far into your game then run all simulation (player and otherwise) at a fixed rate.  60Hz is probably a reasonable choice and just let the game slow down if too much computation is happening.  Keep it simple to start with.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (42 views)
2014-10-16 15:22:06

Norakomi (32 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (85 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!