Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (tomaslolo), 1,542 guests, and 12 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
framerate independent??? #416746
02/03/13 23:57
02/03/13 23:57
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
This code is framerate dependent.. However, when I add "time_step" in "accelerate", it's still framerate dependent??
Code:
function blah(){
	
	camTiltResult = accelerate(camTiltSpeed, -dist.x * 4, 0.8);
	camRollResult = accelerate(camRollSpeed, -dist.y * 4, 0.8);
	
	camera.tilt = camTiltResult;
	camera.roll = camRollResult;
}

WTF is going on? What should I do, to fix this problem? Adding time_step, makes it even worst..


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: framerate independent??? [Re: 3run] #416748
02/04/13 00:10
02/04/13 00:10
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
accelerate yourself wink

Code:
velocity = velocity + acceleration * time_step - velocity * friction;
speed = speed + velocity * time_step;



Visit my site: www.masterq32.de
Re: framerate independent??? [Re: MasterQ32] #416750
02/04/13 08:31
02/04/13 08:31
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
So, basicly, I need to change:
Code:
camRollResult = accelerate(camRollSpeed, -dist.y * 4, 0.8); 

camera.roll = camRollResult;

with this:
Code:
camRollResult = camRollResult + (-dist.y * 1.5 * time_step) - camRollResult * 0.2;
camRollSpeed = camRollSpeed + camRollResult * time_step;

camera.roll = camRollResult;

Right? Anyway, if I change fps_max from 60 to 20 or 500, the results are different.. frown So it's still framerate dependent.

Edit: I tried to add it to camera with "time_step" as well... but still doesn't work.
I simply can't get it! Why the hell I need to use "time_step" already two times?

Last edited by 3run; 02/04/13 08:40. Reason: 12345

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: framerate independent??? [Re: 3run] #416752
02/04/13 09:04
02/04/13 09:04
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Simply use some math:
Code:
mFPS = (16/time_frame);

speedGradient = 60 / mFPS;
tiledGradient = mFPS / 60;



And multiply your time_step with this.
It depends on how you want the code, so choose from my examples wisely, one will make it even more faster, one will slow it down so its always same speed wink

Use the 60 at all if the speed on framerate 60 is the one you wish to have!

Last edited by Ch40zzC0d3r; 02/04/13 09:04.
Re: framerate independent??? [Re: Ch40zzC0d3r] #416764
02/04/13 11:32
02/04/13 11:32
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Things are still not clear for me.. I can't understand, why the example above is framerate dependent!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: framerate independent??? [Re: 3run] #416773
02/04/13 12:48
02/04/13 12:48
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Well you subtract a value each frame without using time_step at the end of this line:
camRollResult = camRollResult + (-dist.y * 1.5 * time_step) - camRollResult * 0.2;

If you smoothly want to adjust angles, use something as follows:

camera.tilt += ang(target_tilt - camera.tilt)*0.25*time_step; // the factor should be lower than 1
or if that is too fast use clamp:
camera.tilt += clamp(ang(target_tilt - camera.tilt)*0.25,-5,5)*time_step;

Now the adjustment will (possibly) start at maximal speed, so you would have to use a second variable/ a different approach, for example as follows (untested, maybe needs some bugfixing):

i = ang(target_tilt - camera.tilt)*0.25;
camera_tilt_speed = minv(camera_tilt_speed+0.25*time_step,minv(abs(i),5));
camera.tilt += clamp(i,-camera_tilt_speed,camera_tilt_speed)*time_step;


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: framerate independent??? [Re: Superku] #416775
02/04/13 13:56
02/04/13 13:56
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Well, this doesn't work as well.. Whats wrong? I can't still clearly understand.. Seems that using "time_step", doesn't help in some cases?
Quote:
camTiltResult = accelerate(camTiltSpeed, -dist.x * 2, 0.2);
camRollResult = accelerate(camRollSpeed, -dist.y * 2, 0.2);

baseAngle.pan = 0;
baseAngle.tilt += ang(camTiltResult - baseAngle.tilt) * 0.25 * time_step;
baseAngle.roll += ang(camRollResult - baseAngle.roll) * 0.25 * time_step;

camera.pan = 0;
camera.tilt = baseAngle.tilt;
camera.roll = baseAngle.roll;
Adding "time_step" into the acceleration doesn't help as well.. What am I missing???


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: framerate independent??? [Re: 3run] #416776
02/04/13 14:10
02/04/13 14:10
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Just don't use accelerate if you have such problems with it, I've never used it.
i = ang(target_tilt - camera.tilt)*0.25;
camera_tilt_speed = minv(camera_tilt_speed+0.25*time_step,minv(abs(i),5));
camera.tilt += clamp(i,-camera_tilt_speed,camera_tilt_speed)*time_step;
Works fine, I've tested it now.
The other examples from my previous post work, too, and framerate independent (at least as long as fps >= 16).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: framerate independent??? [Re: Superku] #416780
02/04/13 15:09
02/04/13 15:09
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Ok, please explain a bit more this lines. What is "target_tilt"? Is it the end angle, that we accelerate to? Other lines seems to be OK for me, I can understand them. As I need to change angles, depending on the input/movement speed, I guess I need to change the first line, to make it work. Or am I missing anything?


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: framerate independent??? [Re: 3run] #416781
02/04/13 15:19
02/04/13 15:19
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Ok I see I should have commented it a little. Have a look at the test code that I've written earlier:

Code:
var i;
var target_tilt = 0;
var target_counter = 48;
var camera_tilt_speed = 0;

[...]

target_counter = maxv(target_counter-time_step,0);
if(!target_counter)
{
	target_tilt = -35-target_tilt; // switch between 0 and -35
	target_counter = 64; // every 4 seconds
}

i = ang(target_tilt - camera.tilt)*0.25;
camera_tilt_speed = minv(camera_tilt_speed+0.25*time_step,minv(abs(i),5));
camera.tilt += clamp(i,-camera_tilt_speed,camera_tilt_speed)*time_step;


This code is useful when target_tilt only changes every now and then, f.i. in a cut scene or something like that. The line

camera_tilt_speed = minv(camera_tilt_speed+0.25*time_step,minv(abs(i),5));

makes sure that the change in camera starts smoothly, not at full speed, in particular the minv(abs(i),5) "resets" the speed value to a low value without an if clause when the target angle is close.

Depending on the actual purpose of your code (I'm not really sure what it will be used for) it may be a better choice to use one of the two other approaches, f.i. when the target angles change quickly.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1