0
\$\begingroup\$

I'm trying to make a character do a short hop or dash. The player doesn't have control of the character for the duration of the dash, which is supposed to be about .4 seconds.

I tried several ways of doing this... I made a different state that the player is in for that amount of time by creating a float like targetTime and checked when Time.time became bigger than targetTime to give back control to the player. Or I could make a float variable like stateTimer and subtract Time.deltaTime each time.

What I noticed is that depending on whether I test the game in the window or maximized, the distance of the dash changes. The game runs noticeably smoother in maximized mode, and depending on the way I calculate movement, the dash goes further or shorter.

The smoother the game runs, the smaller Time.deltaTime becomes, so in an optimal case, targetTime and Time.time would line up exactly. But the larger deltaTime is, the more it can "overshoot" the targetTime and lead to different results, especially when the time frame is only half a second...

When the game runs in windowed mode, deltaTime ranges from around 0.03 to 0.06, which can overshoot quite a bit, but when it's maximized it's around 0.007, around 10 times smaller.

Is there a way to circumvent this? I have no idea how else I'd measure a time frame as short as .4 seconds. Or should I just not bother because the compiled game should run smoothly anyhow (not planning on making it very demanding hardware wise)

I tried around with fixedDeltaTime but that didn't lead to any good results...

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You might want to show us the code that you use. \$\endgroup\$
    – Vaillancourt
    Aug 13, 2019 at 0:55
  • \$\begingroup\$ It sounds like you might not be correcting for the amount of "loose change" you have left in your dash, depending on when the last frame hits relative to the end of the dash. As Alexandre Vaillancourt says, we will need to see your code to tell you how to fix it. \$\endgroup\$
    – DMGregory
    Aug 13, 2019 at 1:39

0

You must log in to answer this question.

Browse other questions tagged .