Java-Gaming.org
 Featured games (81) games approved by the League of Dukes Games in Showcase (498) Games in Android Showcase (114) games submitted by our members Games in WIP (563) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 [LibGDX] Quite noticeable difference from delta-time  (Read 1239 times) 0 Members and 1 Guest are viewing this topic.
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?
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;   }} `

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?
ClickerMonkey

JGO Coder

Medals: 20

Game Engineer

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

We've all been there my friend.

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

I'd strongly suggest using fixed time-steps for simulation in future projects.
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?
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.
 BurntPizza (12 views) 2014-09-21 02:42:18 BurntPizza (11 views) 2014-09-21 01:30:30 moogie (13 views) 2014-09-21 00:26:15 UprightPath (23 views) 2014-09-20 20:14:06 BurntPizza (27 views) 2014-09-19 03:14:18 Dwinin (40 views) 2014-09-12 09:08:26 Norakomi (70 views) 2014-09-10 13:57:51 TehJavaDev (96 views) 2014-09-10 06:39:09 Tekkerue (49 views) 2014-09-09 02:24:56 mitcheeb (70 views) 2014-09-08 06:06:29
 BurntPizza 37x Riven 18x Rayvolution 18x basil_ 16x ags1 16x princec 16x KevinWorkman 15x LiquidNitrogen 12x deathpat 11x kevglass 11x nsigma 11x theagentd 11x HeroesGraveDev 8x Gibbo3771 6x cylab 6x EgonOlsen 6x
 List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50List of Learning Resources2014-07-31 16:29:50List of Learning Resources2014-07-31 16:26:06List of Learning Resources2014-07-31 11:54:12HotSpot Optionsby dleskov2014-07-08 01:59:08
 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