Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (683) Games in Android Showcase (196) games submitted by our members Games in WIP (751) 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 2313 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.

 orrenravid (213 views) 2016-07-16 03:57:23 theagentd (284 views) 2016-07-11 14:28:54 Hydroque (370 views) 2016-07-06 05:56:57 Hydroque (523 views) 2016-07-03 08:52:54 GrandCastle (396 views) 2016-07-01 09:13:47 GrandCastle (388 views) 2016-07-01 09:09:45 CopyableCougar4 (441 views) 2016-06-25 16:56:52 Hydroque (416 views) 2016-06-22 02:17:53 SwampChicken (382 views) 2016-06-20 13:22:57 SwampChicken (305 views) 2016-06-20 13:22:49
 Archive 30x Slyth2727 24x Brynn 23x EgonOlsen 22x orangepascal 22x TritonDreyja 21x orange451 20x DavidBVal 19x Spasi 18x KaiHH 12x LiquidNitrogen 11x Phased 11x Opiop 11x princec 11x Longor1996 10x h.pernpeintner 9x
 Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42FPS Camera Tutorialby Hydroque2016-05-22 05:40:58Website offering 3D Models specifically for games for freeby vusman2016-05-18 17:23:09Website offering 3D Models specifically for games for freeby vusman2016-05-09 08:50:56Website offering 3D Models specifically for games for freeby vusman2016-05-06 11:10:21Website offering 3D Models specifically for games for freeby vusman2016-04-29 12:56:17
 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