Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Announcements and Showcase
delta Time problems

Robo
Guest
Quote
2021-08-27 14:26:53

I felt this was so important I'm putting this here in this thread as an announcement - especially as it relates to multiple posts here.

DONT use the basic 'deltaTime' in your programming when you need smooth flowing graphics to adjust for slowed framerate.

At full speed the numbers come out at alternating 15 & 16 every 2nd frame...in other words its not constant nor accurate enough to use per frame with almost 7% change on every frame - it causes jittering animations.

I was using 'smnmhmdy' excellent FPS controller but had issues with jittering character movement when matching it to the camera rotation no matter what I did - the 'deltaTime' was the culprit and removing it totally solved my issues. Now is butter smooth like a pro..

If you want to use delta-time somehow then do an average based over at least 3 cycles and use that instead.


Robo
Guest
Quote
2021-08-27 15:10:03

The problem mainly lies in using the 'Time' from :
"prototype.onAnimate = function(node, Time) {"

if you instead recode it like this will make it much better:

this.Time = new Date().getTime();
this.deltaTime = this.Time - this.lastTime;
this.lastTime = this.Time;


Guest
Guest
Quote
2021-08-27 19:56:09

@Robo

shouldn't it be timeMs instead of Time?


Guest
Guest
Quote
2021-08-27 21:45:09

@Robo

This is a modified version of a behavior I found on the forums. It doesn't alternate 15 to 16 every other frame, but it still does so every so often.

/*
<behavior jsname="behavior_DeclareDeltaTime" description="Declare delta time">
<property name="PrintDeltaTime" type="bool" default="false">
</behavior>
*/

behavior_DeclareDeltaTime = function(){

this.deltaTime = 0;

this.lastTime = 0;

};


behavior_DeclareDeltaTime.prototype.onAnimate = function() {

var now = (new Date()).getTime();

this.deltaTime = now - this.lastTime;

this.lastTime = now;

if (this.PrintDeltaTime == true) {

print(this.deltaTime);
}
};



Robo
Guest
Quote
2021-08-28 02:19:55

No it doesnt have to be called 'timeMs' - like most variables in CC can be called a lot of things.

So long as you are using the lookup "new Date().getTime();" each frame will be pretty good then only with occasional change will be seen which is acceptable I guess.


smnmhmdy
Registered User
Quote
2021-08-31 11:36:48

Thanks a lot for sharing this info, this explains a lot of my problems with the slight but annoying jitteriness of some of my projects, glad you discovered the issue and even found a solution for it!


just_in_case
Moderator
Quote
2021-09-01 05:29:33

This is so useful thanks for sharing @Robo 😇


Robo
Guest
Quote
2021-09-02 08:05:18

cheers guys...glad to help.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inter?ational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact