Odd character dash discrepancies. Time.deltaTime?

Hey guys, so here’s the deal.
I have a dash counter, dashTimeMax (how long a dash should take. set to 0.5 seconds) and a dash speed, dashSpeed, of 4 mps. So, in theory, I’m expecting my character to move 2 meters after 1 dash execution.
Thing is, I’m getting results that go from 1.92 (maybe less) meters to 2.08 meters, and I don’t know why?

Here’s my code:

On Update:

void UpdateDashStatus()
	{
		if(grounded && downButtonPressed && jumpButtonPressed && !isDashing)
		{
			isDashing = true;

			jumpButtonPressed = false;
			
			dashTimeCounter = dashTimeMax;
		}
		
		if(isDashing)
		{
			dashTimeCounter = dashTimeCounter - Time.deltaTime;

			if(dashTimeCounter <= 0f)
			{
				//print (Time.deltaTime);
				//print (transform.position.x);
				isDashing = false;
			}
		}

	}

On FixedUpdate:

void PerformDash()
	{
		if(isDashing)
		{
			if(facingRight)
				rigidbody2D.MovePosition(rigidbody2D.position + new Vector2(dashSpeed, 0) * Time.deltaTime);
			else
				rigidbody2D.MovePosition(rigidbody2D.position + new Vector2(-dashSpeed, 0) * Time.deltaTime);
		}
	}

Shouldn’t the uses of deltaTime, and of PerformDash() inside of FixedUpdate be giving me sharp results?

If needed, I’ll try to provide further details.
Thanks.

Well, you do execute your dash OnFixedUpdate, and you update your condition on Update. This can cause certain discrepancies, especially for small values of dashTimeMax, like your case.

For example at Update, you check dashTimeCounter and it is >0, so you keep isDashing as true. Later, on FixedUpdate, you execute your dash, but more time has passed since Update, so maybe your dash should have ended, but your condition was evaluated earlier.

You could try to move your Update code to FixedUpdate to decrease your error.

I had a similar issue. I moved my dash related code to fixedupdate and now I get a consistent dash distance. However, now the player stutters when they dash. Have you had a similar issue? @haskell33