TransWikia.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!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP