Yield waitForSeconds inconsistency

Hey, i discovered an inconsistency in my characters dash ability. The lenght varies for some reason, i think the reason is because i time it in a couroutine. So when the dash starts, a courotine starts counting down with yield waitForSeconds, while its counting i move my player with rigidbody.MovePosition, and then stop when it ends. But this give me a problem where ca. 1/10 of times i dash, the dash will be slightly shorter or longer. The offset always seem to be the same. Any idea if this is whats causing it? If so is there a way to fix it, or do i need to redo the way i time my jump?

Im not sure i understand the problem myself, so sorry if i explained it poorly, thanks for any help provided.

Check out the documentation for WaitForSeconds. Perhaps you would have better results using WaitForSecondsRealtime instead.

Especially note the following information.

There are some factors which can mean the actual amount of time waited does not precisely match the amount of time specified:

  1. Start waiting at the end of the current frame. If you start WaitForSeconds with duration ‘t’ in a long frame (for example, one which has a long operation which blocks the main thread such as some synchronous loading), the coroutine will return ‘t’ seconds after the end of the frame, not ‘t’ seconds after it was called.

  2. Allow the coroutine to resume on the first frame after ‘t’ seconds has passed, not exactly after ‘t’ seconds has passed.

Here is the documentation on WaitForSecondsRealtime. Unity - Scripting API: WaitForSecondsRealtime

Could you try changing your WaitForSeconds to WaitForSecondsRealtime and let us know how that goes?

Please provide code you are using for this dash, there could be a bug in it.