Frame skip problem

Posted By: LawnmowerMan

Frame skip problem - 01/21/16 15:47

In my code I use next example for play some function
Code:
if(button_pressed == 1 && my.animation > 80 && my. animation < 85)
{
start function
}

It works well if everything is fine with the frame rate, but if the fps drops, simply this part of animation is skipped and my function wont start. What should I do to prevent the frame skip? I use time_step for play my animations.
Posted By: EpsiloN

Re: Frame skip problem - 01/21/16 21:40

Maybe try testing against .frame ?
Code:
If my.frame > anim start frame && my.frame < anim end frame


Also, just a suggestion, don't limit the upper frame boundary, make a check to see if the animation already played some function this loop and reset it after the animation loop ends. This way, no matter what, the function will trigger at 80% or above.

PS.: Keep in mind, that working with animate functions means working with percentage, while accessing the ".frame" skill means direct access to the current frame number that is being played (no matter if its in the middle of interpolation between the next frame, I think)... so you could trigger it every time on a specific frame.
Posted By: Reconnoiter

Re: Frame skip problem - 01/22/16 11:11

Yeah cause of time_step and slow fps my.animation probably almost never becomes between 80 and 85.

I would use a variable your entity skill as check (make non-zero when you need to call the function and make zero again when you call the function).

But it seems EpsiloN's idea is cleaner so try that first.

ps: is it only for 1 entity?:
Code:
if(button_pressed == 1 && my.animation > 80)
{
  button_pressed = 0;
  ...
}

Posted By: LawnmowerMan

Re: Frame skip problem - 01/22/16 19:09

Thank you guys for help, I already know this should works with only my.frame > 80 but I need that upper limit because exactly in this part of the animation player make the choice of whether something will happen or not. I tried to use fps_min and fps_max but did not help. I guess I have to make it in some other way
Posted By: Superku

Re: Frame skip problem - 01/22/16 19:31

"> .. <" cases are generally a bad idea in such a time sensitive case.
Using a secondary variable as already suggested is (IMO) the correct approach, I do that too.

Code:
my.anim +...
if(my.anim < 80) my.do_action = 1;
else
{
  if(my.do_action)
  {
    my.do_action = 0;
    ... do something
  }
}



Using fps_min is not the worst idea, in general. I have it set to 15 and I make sure everything works fine (including flying projectiles/ movement/ moving platforms/ ...) at that low framerate, and with fps_min the code and gameplay will work on all systems with a non-zero FPS that way.

Btw. if you really need something to start at let's say (anim == 80), then increase it to that value first (with a limit to 80), then do your action and continue up to 100 after that.
Posted By: LawnmowerMan

Re: Frame skip problem - 01/23/16 16:32

Thank you Superku I will follow your suggestion and try with second variable. Can you please explain why you use so low fps_min? In my game I use fps_min 50 and fps_max 60, is it okay? I think it's better if the game goes slow, but to comes to big frames skipping. I control a lot of things in the game through animation, and I fear that my game would not work well on weaker PC. I'm not sure that fps_min really can help here.
Posted By: EpsiloN

Re: Frame skip problem - 01/23/16 18:10

If you use fps min, I think, you're limiting the minimum FPS to 50, but only for calculations. Pentium II cant give you 50 fps... laugh

Another thought to try out,
think how many frames you have for this certain animation, and how fast you go through them in frames/sec and model frames/sec.
If you have to, reduce or increase the number of frames on the model itself (will need additional animation laugh but its the only other thing to try out after everything else...)
© 2023 lite-C Forums