AnswerBun.com

Player can only dash towards to the top right, but can't in any other direction?

Game Development Asked on November 14, 2020

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;
    }   


}

Add your own answers!

Related Questions

Compute shader: Property at kernel index is not set

1  Asked on November 2, 2021 by glen-pierce

   

How can I cast light onto a sprite in 3D environment?

1  Asked on November 2, 2021 by vern-rowan

   

How to run skactions randomly

0  Asked on November 2, 2021 by why25

   

AntiGravity Vehicle?

1  Asked on November 2, 2021 by roswell

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir