Jump to content


Photo
* * * * * 5 votes

Delta time usage


  • Please log in to reply
32 replies to this topic

#1 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 09 October 2012 - 12:16 AM

  • Title: Delta time usage
  • Description: Complete tutorial on how delta_time works and should be used in GameMaker projects
  • GM Version: GameMaker Studio (all platforms)
  • Registered: No.
  • File Type: .gmz
  • File Size: 335kb
  • File Link: Dropbox link
  • Required Extensions: No.
  • Required DLLs: No.

Summary
This tutorial requires basic knowledge from basic GML functions, so please dont ask those in here, I made this merely to explain delta timing for those who doesnt know what it is, or just doesnt know how to apply it on a real game. Also, beware that this only works on the latest GameMaker:Studio releases, I wont explain how to do this on previous versions since it requires .dll files and its only natively supported on GM:S, that said, lets cut the cheese biggrin.gif

What is delta timing??
Delta timing reffers to the time elapsed in betweem frames, tipically used to elliminate the effects of lag nor slowdowns on games to avoid players perceiving them or at most, taking advantage of those situations.
Delta time is measured in microseconds and it only needs to be measured once.
Wikipedia link

How do I use it?
Before starting with the code themselves there are a few notes to be made about how GML uses delta timing. First off, everything is made with the delta_time variable, when the function was first implemented on GM:Studio (formerly delta_time()), it was necessary to use it only once between steps, since it calculated the time between one call and another. This method was, after all, a bit of a headache, so they replaced it with this new read-only global variable, wich can now be used many times on the same step without affecting the output.

Thats great, now show meh the codes!
Ok, first you should set the room speed to something big, I usually set it to 9999 and it result on the game running at max fps all the time. Once that is done, create a controller object, once you have your controller ready and placed on the room, add this on its create event:

globalvar delta;
delta = 1;

We set it to one to avoid possible issues on the first step after its declaration.
Now, add a begin step event on the same controller object with this piece of code:
delta = 60/1000000*delta_time;

Here is the fun part, it is actually a pretty simple calculation; since delta time is measured in microseconds (1.000.000th of a second), we divide our desired standard speed (60fps) by a million, and multiply it by the microseconds that have passed since the last frame, for example, lets say that 25000Ms have passed since the last step:

delta = 60/1000000*25000
delta = 0,00006*25000
delta = 1.5

This means that, on that frame, every movement made must be multiplied by 1.5 to accomplish the lag from the last step. It also means that, since our base speed is 60, the game is actually running at 40fps.

There are many ways to put this into a game, and actually, you can put it pretty much everywhere to make your game run at the same speed, or even make calculations with it! there are only a few places where you just cant use it, or at least, it would be better not-to use it:
  • Alarm events: You can always use something like alarm[0] = 30*delta;, but this is not recommended on games where fps fluctuate a lot, like on mobile platforms and heavy games. The solution is to create custom counters that decrease the speed on a step basis, and when the couter, eg, reaches zero, execute the desired actions.
  • Physics: You can always modify the physics world speed, but modifiyng it based on the delta time could give unexpected results (havent really experimented enough with the physics engine myself)
  • default objetcs speed/gravity/move functions: I highly encourage people to stop using theese, and replace them with cusom variables, since you cna have much more control over them, but if you must, you can always use the same method: speed = 5*delta; on a step event, of course.

That said, let me explain where you should use it, and how you could implement it on your already-built game:

  • Transitions: If you ever come to a situation where you increased the value of a variable on a step-basis to accomplish an event, or just to move trough different stages, screens, etc. you can simply multiply the newly-added values by delta, and it should be it!
  • Movements: When using all kinds of movements, like using the x+=sp methods, or even hpeed, just multiply the base speed by delta.
  • Timers: Same as with transitions. If you ever have to count, for example, the seconds that have passed from the timer start, add delta and you will get the real time, regardless of lag.
  • Pausing: This is extremely simple and yet powerful feature delta time allows you to make. To pause the whole game, just set delta = 0; after the delta calculation, this will stop all movements that are delta time based.


Basic weapon reload & fire example
Following the previous guidelines, and assumming you already have a controller object with the given codes and you have set the room speed to something big, like 9999, I will show you how to create a simple weapon-reload thingy, just to show an example case of use.

First we need an object to shoot, so create an object labeled ball_obj and assign it a simple sprite, wichever you like (a ball, maybe?)
Now, on its step event, put this piece of code, to make it move:

x += lengthdir_x(spe*delta, dir);
y += lengthdir_y(spe*delta, dir);

Do notice I am not using the default speed and direction variables, this is because I like to have more control on how objects move! you can use them if you like, im not stopping you!
Also, notice the spe*delta part there. That is the same code we have been using before, but now inside the lengthdir fctions. This allows the ball to move at the same speed all the time.

Now, we need something to fire the balls, so go ahead and create a object labeled weapon_obj and drop it on the middle of the room. Now, add a create event to it and put this code:
reload = -1;

Nothing else! the juice comes on the step event:
if reload > 0 {
reload -= 1*delta;
}

if keyboard_check(vk_space) && reload < 0 {
reload = 60;
obj = instance_create(x, y, ball_obj);
obj.dir = point_direction(x, y, mouse_x, mouse_y);
obj.spe = 5 * delta;
}

Most of the code is to actually create the bullets and assign them a speed and direction, the part we care about is the reload -= 1*delta;. By doing this we are decreasing the factor of speed we obtained when caculating the delta variable, on the controller event. So, once the reload variable goes from 60 to zero it should have passed exactly one second.
Now, if you want it to fire, say 2 bullets per second, just change the reload = 60; part for reload = 30;.

You can download the complete example from My dropbox, it contains the whole thing, you just ned to create a new empty project and import the .gmz there smile.gif


Please feel free to ask questions regarding the subject, I will do my best to respond them, or if there is anything missing, to add it!

Thanks for reading!

- Manuel777

Edited by Manuel777, 25 August 2014 - 06:29 PM.

  • 15

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#2 Primoz128

Primoz128

    GMC Member

  • GMC Member
  • 323 posts
  • Version:GM:Studio

Posted 10 October 2012 - 11:00 AM

GM Studio only ? Really, have you tried it on Gm 8.1 ?
  • 0

Looking for a coding partner for my space RTS solar conquest project. More information: http://gmc.yoyogames...opic=563123&hl=


#3 AndrewBGM

AndrewBGM

    GMC Member

  • GMC Member
  • 199 posts
  • Version:GM:Studio

Posted 10 October 2012 - 10:58 PM

GM Studio only ? Really, have you tried it on Gm 8.1 ?

GameMaker 8.1 doesn't have delta_time so I'm pretty certain it won't work.

Edited by AndrewBGM, 10 October 2012 - 10:58 PM.

  • 0

I reject your reality and substitute my own.


#4 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 11 October 2012 - 02:52 AM

GM Studio only ? Really, have you tried it on Gm 8.1 ?

GameMaker 8.1 doesn't have delta_time so I'm pretty certain it won't work.

That is correct!

I wont explain how to do this on previous versions since it requires .dll files and its only natively supported on GM:S


  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#5 csanyk

csanyk

    GMC Member

  • GMC Member
  • 624 posts
  • Version:GM:Studio

Posted 12 October 2012 - 07:47 PM

Correction on your units; you're using milliseconds incorrectly
Millisecond == 1/1000th of 1 second == 0.001 second == 1ms
Microsecond == 1/1,000,000th of 1 second == 0.000001 second == 1μs


Edited by csanyk, 27 September 2013 - 08:40 PM.

  • 0

#6 csanyk

csanyk

    GMC Member

  • GMC Member
  • 624 posts
  • Version:GM:Studio

Posted 12 October 2012 - 07:51 PM

Another thing I'll point out, setting delta = 0 does not truly pause the game -- any objects that are in collision will continue firing collision events every step while the game is "paused", which could have undesired effects, and you'll need to deal with that somehow.  The easiest thing to do being to put a big if delta != 0 conditional around all the code in your collision events: 


Edited by csanyk, 06 January 2016 - 10:49 PM.

  • 1

#7 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 12 October 2012 - 08:41 PM

Yes, I am aware of that; but it does work for pausing movement and even particles (when you set auto update on particles off).. you could add an if surrounding the desired collission events to check if the game is paused or not, that would be my solution.
On my games, I am not setting any blocks for that; if there is a collision its Ok to trigger it because it is a shooter game and collsisions happen only once. On RTS, RPGs and that kind of games where therea are constant collissions it is extremely necessary to add a collision block like the described bove.

Ps: Fixed the microsecond thingy, thanks!

Edited by Manuel777, 12 October 2012 - 08:42 PM.

  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#8 TemplarX2

TemplarX2

    GMC Member

  • GMC Member
  • 111 posts

Posted 09 January 2013 - 07:07 PM

Comment before I tested Manuel's method:If you set the fps to a large number, then you are forced to use the variable delta everywhere to simulate the desired room speed (say 60). But this will lead to complication as only a few variables (such as speed and direction) requires delta time while others can be ignored (such as some animation speeds). Multiplying everything by delta use processing power too.

Comment after I tested Manuel's method: I actually see the merits of your method. I really must applaud you. I can also see the online potential by manipulating x and y coords instead of using variables like speed and direction.

Edited by TemplarX2, 10 January 2013 - 09:57 AM.

  • 0

#9 Xnite

Xnite

    GMC Member

  • GMC Member
  • 47 posts
  • Version:GM:Studio

Posted 30 August 2013 - 03:30 AM

Thanks for the great tutorial.

 

One question. How much extra overhead do you think using this system adds to a game, in terms of extra processing power needed. I'm planning a game that has a small section of the design that requires slow mo. However, I'm already concerned about performance due to one of my target platforms being the ouya. So I'm tempted to sacrifice the slow mo feature so that I don't have to use a delta time system and add the extra processing (and for me complexity to the code). I know its probably not an easy question to answer due to the huge amounts of variables but wondering if you have any thoughts on this?


  • 0

#10 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 30 August 2013 - 04:32 AM

Thanks for the great tutorial.

 

One question. How much extra overhead do you think using this system adds to a game, in terms of extra processing power needed. I'm planning a game that has a small section of the design that requires slow mo. However, I'm already concerned about performance due to one of my target platforms being the ouya. So I'm tempted to sacrifice the slow mo feature so that I don't have to use a delta time system and add the extra processing (and for me complexity to the code). I know its probably not an easy question to answer due to the huge amounts of variables but wondering if you have any thoughts on this?

 

I dont think it affects performance at all, especially if you define delta as a global variable and reuse it troughout all of the objects that needs to access to it, since after that initial calculation (wich is deprecable already) you ust need to multiply a number.

 

I wouldnt worry about that at all, this is actually for improoving performance (or at least hide the slowdowns)  :)


  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#11 BlueBurn

BlueBurn

    GMC Member

  • GMC Member
  • 139 posts
  • Version:GM:Studio

Posted 03 March 2014 - 08:59 PM

Well, it looks like it doesn't work in the later version, does it ?


Edited by BlueBurn, 03 March 2014 - 09:01 PM.

  • 0

#12 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 04 March 2014 - 04:15 AM

Well, it looks like it doesn't work in the later version, does it ?

 

May be the .gmz, will check, but the methods and scripts described in the first post are still valid, as I use them constantly.


  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#13 pablo1517

pablo1517

    GMC Member

  • GMC Member
  • 399 posts

Posted 03 April 2014 - 08:41 PM

 

 

delta = 60/1000000*25000
delta = 0,00006*25000
delta = 1.5

Lol, what? Why make 2/2*2 equation?

global.delta = delta_time/1 000 000;

will give the correct multiplier value no matter what room speed you have.


Edited by pablo1517, 03 April 2014 - 08:52 PM.

  • 0

If I helped then feel free to press this button rep_up.png under my post  ;)


#14 Lonewolff

Lonewolff

    Permanent Resident

  • GMC Member
  • 3517 posts
  • Version:GM:Studio

Posted 03 April 2014 - 09:10 PM

[quote name="Manuel777" post="4107567" timestamp="1349740961"]Ok, first you should set the room speed to something big, I usually set it to 9999 and it result on the game running at max fps all the time.[quote]

Really? When ever I have tried to set the room speed to something big, room_speed has always capped out at 60 FPS for me. Even though fps_real reports a number into the thousands.

I just assumed that GM:S didn't allow for room speeds above 60.

This was the case with my old PC and also my current one. I am now running an 8 core AMD at 3.5 Ghz, so speed is not an issue.

So, I am a bit bewildered here.
  • 0

#15 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 04 April 2014 - 12:18 AM

FPS dont matter, the whole point of delta time is to not rely on FPS, so if you cpu or gms is capping them you will be okay anyway. Also, any fps above 60 is usually never needed and will give you more smoothnes than what your eye can notice :)

I pointed to set the fps at max speed just so you can see the changes in-game.
  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#16 Lonewolff

Lonewolff

    Permanent Resident

  • GMC Member
  • 3517 posts
  • Version:GM:Studio

Posted 04 April 2014 - 02:01 AM

FPS dont matter, the whole point of delta time is to not rely on FPS, so if you cpu or gms is capping them you will be okay anyway. Also, any fps above 60 is usually never needed and will give you more smoothnes than what your eye can notice :)
I pointed to set the fps at max speed just so you can see the changes in-game.


That's what I am saying though, if I set room speed to 9999 my delta is still 0.0167 (60 FPS).

So, even though my rig is capable of 4000 FPS, I get capped at 60 max with GM:S. That's with vsync on or off.
  • 0

#17 Ground Effect

Ground Effect

    GMC Member

  • GMC Member
  • 63 posts
  • Version:GM:Studio

Posted 24 August 2014 - 03:30 PM

This tutorial does not work correctly for me right away. In order to fix it, I multiplied the obj.spe times global.delta in the keyboard press block of code


  • 0

Check out my creations here: https://marketplace....nd-effect-games


#18 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 25 August 2014 - 06:31 PM

This tutorial does not work correctly for me right away. In order to fix it, I multiplied the obj.spe times global.delta in the keyboard press block of code

 

Whoops!, you are correct, I fixed the example code :)

Also, its worth mention that, in order to keep the speed of the bullets constant you should assign speed * delta in the bullet's step event as well ;)

 

Edit: wait the example tells you to set spe, wich is a variable used in the ball_obj we created, so it should work if you follow the ball_obj step as-is, trough if you are using the built-in speed variable you will have to do as I wrote originally.


Edited by Manuel777, 25 August 2014 - 06:36 PM.

  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#19 Cenderle

Cenderle

    GMC Member

  • GMC Member
  • 74 posts
  • Version:GM:Studio

Posted 05 December 2014 - 07:26 PM

Is there a way to handle timelines with delta time?

Or is it best not to use them, and just set custom counters like you suggest for alarms?


  • 0

#20 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 09 December 2014 - 07:03 PM

Is there a way to handle timelines with delta time?

Or is it best not to use them, and just set custom counters like you suggest for alarms?

 

hm I never use timelines.. but to answer the question; yes, if you want to keep it delta-based either use alarms or user events.


  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#21 ThePC007

ThePC007

    Chickenator

  • GMC Member
  • 1062 posts
  • Version:GM:Studio

Posted 19 December 2014 - 10:51 PM

Managed to get some basic delta time and delta container (yep, had to name it somehow) to work. Basically, the container is there to speed the game up in case too much time is lost in order to make up for that time. It's kind of what Minecraft does.

This topic really helped me out. Thanks for making it. :P


  • 0

#22 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 22 December 2014 - 07:04 PM

Managed to get some basic delta time and delta container (yep, had to name it somehow) to work. Basically, the container is there to speed the game up in case too much time is lost in order to make up for that time. It's kind of what Minecraft does.

This topic really helped me out. Thanks for making it. :P

 

That is what delta time is used for! Glad it helped :D


  • 1

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#23 jaimitoes

jaimitoes

    GMC Member

  • GMC Member
  • 247 posts
  • Version:GM:Studio

Posted 07 January 2015 - 05:20 AM

 I found an issue trying to manage all instance speed with delta,i made animations with spine,creating the variable for image_speed, room in 600, i create a slowmotion decreasing the delta value putting this :

 

//Create event

 

delta_scale =60;

delta = 1;

 

//Step event

 

 

delta = delta_scale/1000000*delta_time;

if (key_left)

 

{

 delta_scale+=0.1;

}

else if (key_right)

{

 delta_scale-=0.1;

}

 

   With that you can do a manual slowmotion (only for experiments)....and works fine!!

But the problem is when i put V-Sync to avoid tearing,  the fps blocks on 60-64 and delta_scale do not work....

 

Alguna Idea Manuel? 


Edited by jaimitoes, 07 January 2015 - 05:42 AM.

  • 0

#24 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 09 January 2015 - 09:22 PM

I found an issue trying to manage all instance speed with delta,i made animations with spine,creating the variable for image_speed, room in 600, i create a slowmotion decreasing the delta value putting this :
 
//Create event
 
delta_scale =60;
delta = 1;
 
//Step event
 
 
delta = delta_scale/1000000*delta_time;
if (key_left)
 
{
 delta_scale+=0.1;
}
else if (key_right)
{
 delta_scale-=0.1;
}
 
   With that you can do a manual slowmotion (only for experiments)....and works fine!!
But the problem is when i put V-Sync to avoid tearing,  the fps blocks on 60-64 and delta_scale do not work....
 
Alguna Idea Manuel?

 
Well, the slow motion should work even when settings the fps to something as low as that, since fps dont matter anymore when we use delta time (unless we are doing something wrong and we are actually not using the delta time variable correctly)
 
In your case, instead of changing the value of the "delta scale" variable I would multiply the entire output of 'delta' instead, as that variable should remain static at all times.
 
Create:

delta_scale = 1;
delta = 1;

 
Step:

delta = 60/1000000*delta_time;
delta *= delta_scale;
if (key_left) {
    delta_scale += 0.1;
}
else if (key_right && delta_scale > 0.1) {
    delta_scale -= 0.1;
}

  • 1

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#25 jaimitoes

jaimitoes

    GMC Member

  • GMC Member
  • 247 posts
  • Version:GM:Studio

Posted 12 January 2015 - 08:06 PM

Thank you very much Manuel!!! thats work perfect!!! thanks a lot!


  • 1

#26 Magicwaterz

Magicwaterz

    GMC Member

  • GMC Member
  • 84 posts
  • Version:GM:Studio

Posted 12 May 2015 - 11:10 AM

Will it work on motion planning functions like mp_grid_path? I am using those for my enemy movement. I am still figuring out how to make my own custom gravity variable.


  • 0

Beware of anger meltdowns...

Check my deviantArt account here: http://magicwaterz16.deviantart.com/

Check my tumblr account here: http://magicwaterz16.tumblr.com/


#27 Magicwaterz

Magicwaterz

    GMC Member

  • GMC Member
  • 84 posts
  • Version:GM:Studio

Posted 06 January 2016 - 02:39 PM

I am having issues with delta_time. I used it in my TD since the game runs at 6-7 fps (even on an empty room initially when I started working on it) on the PC I'm working on while 60 fps on other PCs. The projectiles somehow miss the target even though I set the speed to 4 with the delta timing. I tried the lowering it to 1 but it never hits the target instead. I tried removing delta timing and it did hit target whether it was on speed 4 and hits target when up close if it is on speed 1. Do I still need add something?


Edited by Magicwaterz, 06 January 2016 - 03:00 PM.

  • 0

Beware of anger meltdowns...

Check my deviantArt account here: http://magicwaterz16.deviantart.com/

Check my tumblr account here: http://magicwaterz16.tumblr.com/


#28 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 06 January 2016 - 11:33 PM

I am having issues with delta_time. I used it in my TD since the game runs at 6-7 fps (even on an empty room initially when I started working on it) on the PC I'm working on while 60 fps on other PCs. The projectiles somehow miss the target even though I set the speed to 4 with the delta timing. I tried the lowering it to 1 but it never hits the target instead. I tried removing delta timing and it did hit target whether it was on speed 4 and hits target when up close if it is on speed 1. Do I still need add something?

 
That probably happens because you are using collision events. If the FPS get too low the bullet will travel a longer distance between frames, and it may go over the wall or target while traveling such long distances.
 
The solution is not using the collsiion events, and instead do something in the step event. I tipically do something like this:
if collision_line(xprevious, yprevious, x, y, target_object, 1, 1) {
    // there is a collission
}

  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#29 Magicwaterz

Magicwaterz

    GMC Member

  • GMC Member
  • 84 posts
  • Version:GM:Studio

Posted 07 January 2016 - 07:58 AM

 

That probably happens because you are using collision events. If the FPS get too low the bullet will travel a longer distance between frames, and it may go over the wall or target while traveling such long distances.
 
The solution is not using the collsiion events, and instead do something in the step event. I tipically do something like this:
if collision_line(xprevious, yprevious, x, y, target_object, 1, 1) {
    // there is a collission
}

 

Oh my gosh! Thank you so much!

I just modified the code into this:

collision_line(xprevious, yprevious, x+lengthdir_x(Speed*delta, direction), y+lengthdir_y(Speed*delta, direction), obj_Parent_Enemy, 1, 1)

This way, it predicts the next point of the projectile and checks if it there's a collision using the speed of the projectile and the delta time.


  • 0

Beware of anger meltdowns...

Check my deviantArt account here: http://magicwaterz16.deviantart.com/

Check my tumblr account here: http://magicwaterz16.tumblr.com/


#30 Derjyn

Derjyn

    GMC Member

  • New Member
  • 6 posts
  • Version:GM:Studio

Posted 02 February 2016 - 03:04 AM

I don't want to sound like a jerk and don't mind this being my first post (I totally lost my old account info)...

 

But is this just broken now? I have dealt a lot with delta timing, starting a long time ago when working with Ogre3D and trying to get a "finger on the pulse" of timing in the engine I was developing. I read a great article over at Gaffer on Games (http://gafferongames...-your-timestep/) that I really like and recommend to anyone touching this area of game development. Basically, I'm no stranger to the concept at play here.

 

The reason I ask about this functioning properly is that when changing that 60 from the bit:

delta = 60/1000000*delta_time

to say a 120 or 80 or whatever, all speeds scale. This doesn't seem right to me, as it's my understanding that utilizing delta time gets rid of the need for adjusting all your speeds and such. I'm guessing that I'm just not getting this implementation of a delta timing system, ha.

 

On the GameMaker documentation, they have a simple example:

speed = spd * (ot - delta_time);

With a description reading:

The above code will set the speed of the instance using delta-time to correct for lag. The variable "ot" would be used to hold the previously calculated delta_time value so that the ratio can be used to multiply the base speed value (held in the variable "spd") and so get a consistent speed for the instance.

 

It seems that layering on top of the base implementation would be redundant? I'm going to test between the base, the version here and others I have come across, but wanted to pop in inquire about this. Again, not trying to be a wet blanket, just want to understand this more!

 

[edit]

Okay, after a bit of testing this is the simplest approach. I need to figure out some maths for image_speed stuff, but outside of that everything seems to work. I guess I was overthinking it all!

[/edit]


Edited by Derjyn, 02 February 2016 - 03:46 AM.

  • 0

#31 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 03 February 2016 - 02:40 AM

I simply use 60 because that is the frame rate I always use, and seemed like an appropiate value to use;

multiplier = frames_per_second / max_delta_time_per_second * delta_time_passed

having a delta multiplier of 1 would result in one real frame of lag having passed, it makes it simpler in my head, for example; if I want to make a timer that lasts two seconds, I would increase the value up to 120, adding the raw multiplier value to the clock on each frame.

 

Edit:

This is not a rule or something static, you can do it any way you want really, even just use delta_time with no changes is fine, as long as you know how to handle it afterwards to get the effect you want.


Edited by Manuel777, 03 February 2016 - 02:41 AM.

  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#32 Derjyn

Derjyn

    GMC Member

  • New Member
  • 6 posts
  • Version:GM:Studio

Posted 04 February 2016 - 07:22 PM

Hey Manuel,

 

I'm chugging along fine now, with the system you cooked up. I just needed more coffee and a clearer brain when I was first working with it, haha! It's slowly finding what I need to change elsewhere, to depend on this timing system that is the fun bit. Some things are just fine as is, others need some love and attention. I'm forming a "world" system, with physics based movements and collisions, etc, as well as weather and all that.

 

What I'm trying to figure out now is, how to manually update physics. It's clearly tied to the FPS (ewwww), so if I say, bind left mouse click to spawn a physics object and start spawning them in, as more come in and FPS starts dropping, the physics simulation slows down. I'm guessing it will be said I can update the physics rate/speed, but I'd rather have control over the physics heartbeat right off the rip. Plus, I don't want to be updating the physics rates every step and such. Not sure if this is possible yet though- my research thus far has turned up not-a-dang-thing ;)


  • 0

#33 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 05 February 2016 - 12:34 AM

What I'm trying to figure out now is, how to manually update physics. It's clearly tied to the FPS (ewwww), so if I say, bind left mouse click to spawn a physics object and start spawning them in, as more come in and FPS starts dropping, the physics simulation slows down. I'm guessing it will be said I can update the physics rate/speed, but I'd rather have control over the physics heartbeat right off the rip. Plus, I don't want to be updating the physics rates every step and such. Not sure if this is possible yet though- my research thus far has turned up not-a-dang-thing ;)

 
Yep, I explain that in the OP, at the moment of writing I did not had much experience with physics and delta, but I tried it once afterwards with some ammount of sucess. I remember it not working as I expected for some silly things, but as far as the speed dependence goes, it worked just fine by updating the speed of the system on-par with the delta variable every step. Trough it was a mess when FPS changed too much rapidly (ie; mobile) as the speed was set for the next frame based on the time that passed since the previous frame, causing some lag. ugh.
 
This is what you need to get it working;
physics_world_update_speed()
  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.