time_step question

Posted By: Logitek

time_step question - 11/11/15 15:26

Hi, I have a question about time_step


I wanna know if my thoughts are correct:

For example: I wanna move a model in a direction. It is not important in which direction. It is only an example.

while(1)
{
model.x += 1;
//At 60 FPS it would move 60 quants in one second.
wait(1);
}

BUT now I wanna do that with time_step in the same speed.

while(1)
{
model.x += time_step * 3.75;
wait(1);
}



My question is: Is 3.75 the correct value to get the same speed? It is without c_move, but that is not the question.

I have found this in the manual:

The duration of the last frame cycle in ticks, i.e. sixteenths of a second. A speed multiplied by time_step gives the distance to be covered per frame. On a frame rate of 16 fps both variables have a value of 1.

So I thought: 1 / 16 * 60frames = 3.75
And also 60/16 = 3.75

Is there a professional who knows if this is correct?



Second question. What if I wanna wait 4 frames with wait(4) at 60 fps. But now with time_step? So that it would be only 2 frames at 30 fps? Because 30 fps is only the half of 60. So wait(4) would take the double time as at 60 fps.

Posted By: Superku

Re: time_step question - 11/11/15 16:39

Originally Posted By: Logitek
My question is: Is 3.75 the correct value to get the same speed? It is without c_move, but that is not the question.

Then I don't really understand the question/ issue. Why would c_move be any different?


To your other question: Just get completely rid off the way of thinking with frame rate dependent stuff. It's only getting you in trouble and it's not helping. Don't even try to compare problems with framerate dependent solutions.
You know that the engine works in ticks, like 16 ticks equal one second. Then

my.skill1 = 16;
while(my.skill1 > 0)
{
my.skill1 -= time_step;
wait(1);
}

is going to take approximately 1 second. With stuff like that I pretty much do all my code, like

my.skill2 += time_step;
if(my.skill2 > 2)
{
my.skill2 -= 2;
effect(...); // <--- now 8 particles get spawned every second, framerate independent
}
Posted By: Logitek

Re: time_step question - 11/11/15 16:50

Hey, great. Thank you for that!
Posted By: Logitek

Re: time_step question - 11/11/15 16:53

Originally Posted By: Superku

my.skill1 = 16;
while(my.skill1 > 0)
{
my.skill1 -= time_step;
wait(1);
}

is going to take approximately 1 second. With stuff like that


One more question: wait(-1); is working the same way I think??
Of course, only if it is a second.
Posted By: Superku

Re: time_step question - 11/11/15 17:53

I suggest you don't use wait with a negative argument, it's error prone.
For example when you place wait(-x) at game start the delay will be rather random, depending on loading times or other stuff. It doesn't work with other stuff such as time_factor or maybe freeze_mode (not sure), and in general I find using it a bad practice.
Instead keep it with that manual time_step approach.
Posted By: EpsiloN

Re: time_step question - 11/11/15 20:20

time_step is the duration of the last frame (that is, how much the computer needed to display the last frame) in !ticks!, or 16-ths of a second, meaning, if time_step is equal to 1, the last frame took 1/16 of a second to display on the screen.

It isn't explained well in the manual...

So,
at 60 fps, time_step is roughly equal to 0.267 ticks.
If you want to move your entity with 60 quants per second at 60 fps, you have to do this:
Code:
my.x += (60 / 16) * time_step;


which means:
Code:
my.x += 3.75 * 0.267; // or ~1 quant...every frame...60 quants for 60 frames


!This is frame independent in theory!
At 30 fps, moving 60 quants per second the calculation becomes:
Code:
my.x += (60 / 16) * time_step;


Or
Code:
my.x += 3.75 * 0.533; // or ~2 quants every frame, 60 quants for 30 frames



I hope this sheds some light on that matter laugh

In theory , 16 / time_step should give you the FPS (meaning "wait(16/time_step)" should wait 1 sec.), but I've had my problems the last time I tried it, but it could have been some other piece of code in my game (its around 20k lines, so its hard to notice...)
Posted By: Logitek

Re: time_step question - 11/12/15 07:45

Thank you for the informations.
Posted By: Logitek

Re: time_step question - 11/12/15 11:12

Why I was asking all that questions?

Before I was not really interested in how time_step is working. It was working and that was enough for me.

Until I tried the spider script from the old aums:

spider_speed.x = 8 * time_step;
spider_speed.y = 0;
spider_speed.z = 0;
spider_speed *= time_step; // *


The interesting thing is, that the spider would have the double speed with 30 fps than with 60 fps.

And I know it is the 4th line *

But I don't understand why. It is working fine if I delete this line and change the speed. But I ask myself why this line is included in the script.



Now I have also a question about waiting some frames. Not for particles, only for a break of 4 frames.

For example I wanna wait(4); at 60 fps.

But only wait(2); with 30 fps.

What would be the best solution for that?
Something like wait(3.75 * time_step *4)? Because time_step * 3.75 would be 1.

Sorry for the stupid questions. I only wanna understand the complete process.
Posted By: Superku

Re: time_step question - 11/12/15 13:30

The 4th line is just a bad mistake, nothing else. Maybe the code was using a var with the same name first instead of a Vector.

I already told you how to "wait" frame rate independent, which is why I don't get your new question.
Posted By: Logitek

Re: time_step question - 11/12/15 13:49

Hello.

Okay I understand, thank you for your help.
Posted By: EpsiloN

Re: time_step question - 11/13/15 07:54

3.75 * time_step would give you the opposite result... When the FPS drops, time_step becomes bigger, so it'll give you a bigger value in 30 fps than in 60 fps.

Instead, 16 / time_step will give you the frame rate, multiply by 0.x for fractions of a second, for example, if you want to wait 4 frames out of 60 fps, that's 0.067 of a second ((1/60) * 4), now 16 / time_step * 0.067 will give you the frames needed to wait on different fps.

As for the spider example, this line (4-th) is multiplying the pointer to a vector by time_step, and a pointer is usually just a pointer. It shouldn't make any difference, I have no idea why the spider goes faster...
Posted By: Anonymous

Re: time_step question - 11/13/15 16:03

^ Because this is old pre-lite-c AUM code it is not a pointer at all or for a fact a vector.

Old A5 code I started with. var could be used as a var[3] and accessed with the (dot)xyz

Click to reveal..
Code:
action deadly_spider

{

    var spider_speed;

    var in_front;

    my.enable_entity = on;

    my.enable_impact = on;

    my.event = hurt_them;

    while(1)

    {

       spider_speed.x = 8 * time; 

       spider_speed.y = 0;

       spider_speed.z = 0;

       spider_speed *= time;

       in_front.x = my.x + 40 * cos(my.pan);

       in_front.y = my.y + 40 * sin(my.pan);

       in_front.z = my.z;

       if (content(in_front) == content_solid)

       {

          my.skill40 = my.pan;

          my.skill41 = 30 + random(90);

          while (my.pan < my.skill40 + my.skill41) // rotate 30..120 degrees

          {

             my.pan += 5 * time;

             wait (1);

          }

       } 


       else // free to move

       {

          ent_cycle("run", my.skill20); // play the "run" animation

          my.skill20 += 10 * time; 

          my.skill20 %= 100; // loop 

          move_mode = ignore_passable; // ignore passable entities

          result = ent_move (spider_speed, nullvector);

          if (result == 0) // got stuck?

          {

             spider_speed.x *= -1; // then reverse the movement direction

             my.skill40 = my.pan;

             my.skill41 = 30 + random(90);

             while (my.pan < my.skill40 + my.skill41) // rotate 30..120 degrees

             {

                 my.pan += 5 * time;

                 ent_cycle("run", my.skill20); // play reversed "run" animation

                 my.skill20 -= 10 * time; 

                 my.skill20 %= 100; // loop 

                 move_mode = ignore_passable; // ignore passable entities

                 ent_move (spider_speed, nullvector);

                 wait (1);

             }

            spider_speed.x *= -1; // restore the initial speed

         }

     }

    wait (1);

 }

 wait (1);

}


http://www.coniserver.net/coni_users/web...2_3_3_3_2_2.htm
AUM 42 !!!!

A5 and older code is in on way a simple direct conversion like A6 and pre-lite-c A7 code.

Funny back then lite-c was insane to me, but now that I look back in my mind, WDL was insane !!

Mal
Posted By: EpsiloN

Re: time_step question - 11/13/15 19:52

Ok, I just noticed it being declared as var...but why is there a call to .x/y/z on a single var?

I started with A4, I've used the old stuff, but I don't think you can access .y on a single var? grin Interesting...
Posted By: Logitek

Re: time_step question - 11/14/15 14:43

That's right.

Because normally it has to be: var spider_speed[3] = 0,0,0;
or var spider_speed[3];

in C-Script.

So I wondering why this is running :-)

I have tested it in C-Script and it is running without that declaration.
© 2024 lite-C Forums