Framerate drop cause 8 Direction object to "stutter" and never accelerate to full speed.

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • I have a project using the 3D camera, a twin-stick shooter. When the player inputs movement (via either the keyboard WASD or the Gamepad Analog stick) it runs this function:

    It needs to do this to calculate the angle of the camera and the movement direction, and also lerps to the players maximum speed.

    This works fine provided the system keeps running at a solid 60FPS, but if it drops, the players movement stutters a great deal and either very slowly or never reaches full speed (but mostly only when running it exported, not when previewing it?)

    Any idea on why this is happening and how to fix it? I am half tempted to rip the 8 Direction movement out.

  • It's not really an issue with the 8 Direction behavior, but with how the lerp is implemented. Your code is not framerate independent.

    Framerate independent lerp example:

    lerp(CurrentValue, TargetValue, 1 - (0.05 ^ dt))

    In this example, 0.05 means that after 1 second, only 5% of the difference remains. Lower values = faster / Higher values = slower.

    If the function does not run every tick, then you would need to replace dt with the elapsed time since this function last executed.

    In that case, use the elapsed time since the previous function execution instead:

    lerp(CurrentValue, TargetValue, 1 - (0.05 ^ TimeElapsedSinceLastExecution))

    You should apply this to every lerp.

    Sidenote: Since this code is inside a function and i don't see how it's being executed... the function should run once every tick for the lerping to behave as expected.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Everade ah! That seems so obvious now, in my head I assumed that this didn't need DT because behaviors already utilize DT and I was using a behavior, but that's not the case.

    This function is not called every tick, it is called while the player is inputting a movement direction (which I suppose is every tick that it is needed) and deceleration is handled by the 8-Direction behavior. Would I still need use "TimeElapsedSinceLastExecution" in that case?

  • This function is not called every tick, it is called while the player is inputting a movement direction (which I suppose is every tick that it is needed) and deceleration is handled by the 8-Direction behavior. Would I still need use "TimeElapsedSinceLastExecution" in that case?

    If the function is called once per tick (while movement is active), then you should be good to go.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)