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.