Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (570) Games in Android Showcase (154) games submitted by our members Games in WIP (619) 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 1594 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.

 Riven (24 views) 2015-04-16 10:48:47 Duke0200 (37 views) 2015-04-16 01:59:01 Fairy Tailz (28 views) 2015-04-14 20:13:12 Riven (30 views) 2015-04-12 21:36:37 bus hotdog (47 views) 2015-04-10 02:39:32 CopyableCougar4 (50 views) 2015-04-10 00:51:04 BurntPizza (49 views) 2015-04-06 22:06:58 ags1 (52 views) 2015-04-02 10:58:48 Riven (50 views) 2015-04-01 18:27:05 ags1 (68 views) 2015-03-31 10:55:12
 BurntPizza 24x theagentd 21x wessles 15x Rayvolution 12x kingroka123 11x 65K 11x alwex 10x KevinWorkman 9x kevglass 8x ra4king 8x phu004 8x Ecumene 7x chrislo27 7x Roquen 7x Hanksha 7x Olo 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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