Search Unity

2 Player movement problem

Discussion in '2D' started by simonodube, Feb 23, 2019.

  1. simonodube

    simonodube

    Joined:
    Feb 22, 2019
    Posts:
    5
    So, when i jump, my character's air horizontal mobility becomes really high so he goes super fast.
    And also when i start the game my character is stuck in crouch...

    Code (CSharp):
    1.  public float runSpeed = 22f;
    2.  
    3.     float horizontalMove = 0f;
    4.  
    5.     bool jump = false;
    6.  
    7.     bool crouch = false;
    8.  
    9.     // Update is called once per frame
    10.     void Update()
    11.     {
    12.         horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
    13.  
    14.         if (Input.GetButtonDown("Jump"))
    15.         {
    16.             jump = true;
    17.         }
    18.  
    19.         if (Input.GetButtonDown("Crouch"))
    20.         {
    21.             crouch = true;
    22.         } else if (Input.GetButtonUp("Crouch"))
    23.         {
    24.             crouch = false;
    25.         }
    26.  
    27.  
    28.     }
    29.  
    30.     private void FixedUpdate()
    31.     {
    32.         //Move
    33.         controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
    34.         jump = false;
    35.     }
    36. }
    37.  

    Thanks in advance :)