I have a dash mechanic, but it only seems to be working when the player is going up, down, left, right, or to diagonally to the upper right. It won't work diagonally in any other directions, and I can't figure out why?
The super weird thing is this problem only happens when my game is running on my computer, not on my laptop?? Any ideas on how I can fix this? Thank you!
void FixedUpdate()
{
if (dashing)
{
myRigidbody.AddForce(direction * dashspeed/3,
ForceMode2D.Impulse);
}
else
myRigidbody.AddForce(direction* thrust/4.75f,
ForceMode2D.Impulse);
myRigidbody.AddForce(direction * -thrust * 7f,
ForceMode2D.Force);
}
void Update()
{
direction.x = Input.GetAxisRaw("Horizontal");
direction.y = Input.GetAxisRaw("Vertical");
if (Input.GetKeyDown(KeyCode.Space) & powerSlider.value > 0)
{
if (direction.x != 0 || direction.y != 0)
{
if (CanDash) elapsedTime = 0f;
}
if (elapsedTime < duration)
{
if (!dashing)
{
CanDash = false;
dashing = true;
}
elapsedTime += Time.deltaTime;
}
if (elapsedTime > duration)
{
if (dashing)
{
dashing = false;
elapsedTime = Mathf.Infinity;
StartCoroutine("DashCoolDown");
}
}
if (elapsedTime >= duration)
{
elapsedTime = Mathf.Infinity;
}
IEnumerator DashCoolDown()
{
Debug.Log("dash cooldown");
yield return new WaitForSeconds(.45f);
CanDash = true;
}
}