Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (565) Games in Android Showcase (151) games submitted by our members Games in WIP (605) 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 1534 times) 0 Members and 2 Guests 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.

 theagentd (11 views) 2015-03-27 23:08:20 wxwsk8er (52 views) 2015-03-20 15:39:46 Fairy Tailz (46 views) 2015-03-15 21:52:20 Olo (28 views) 2015-03-13 17:51:59 Olo (30 views) 2015-03-13 17:50:51 Olo (37 views) 2015-03-13 17:50:16 Olo (43 views) 2015-03-13 17:47:07 ClaasJG (56 views) 2015-03-10 11:36:42 ClaasJG (41 views) 2015-03-10 11:33:01 Pippogeek (47 views) 2015-03-05 14:36:23
 basil_ 22x LiquidNitrogen 21x BurntPizza 21x KevinWorkman 21x EgonOlsen 17x theagentd 16x Roquen 16x princec 12x Varkas 10x Riven 10x SHC 9x 65K 9x Ashedragon 8x Ecumene 7x nsigma 7x phu004 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