Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Why there is gameplay difference between those inputs?

Discussion in 'Input System' started by AnnieAlves, Mar 23, 2023.

  1. AnnieAlves

    AnnieAlves

    Joined:
    Jan 10, 2023
    Posts:
    4
    I created a game in my studies, and theres is a coop mode. Player1 and Player2 have two different inputs methods and they behave differently. Player1 seems to have a delay between the time I press the key and the time to execute the command. Player 2 goes to the direction at instant time.
    My code:




    Code (CSharp):
    1.    void CalculateMovement()
    2.     {
    3.  
    4.         if (_PlayerTwo == false)
    5.         {
    6.             float HorizontalInput = Input.GetAxis("Horizontal");
    7.             float VerticalInput = Input.GetAxis("Vertical");
    8.             Vector3 direction = new Vector3(HorizontalInput, VerticalInput, 0);
    9.  
    10.             if (_speedBoostActive == false)
    11.             {
    12.                 transform.Translate(direction * _speed * Time.deltaTime);
    13.             }
    14.  
    15.             else
    16.             {
    17.                 transform.Translate(direction * (_speed * 1.5f) * Time.deltaTime);
    18.             }
    19.                                    
    20.         }
    21.  
    22.         else
    23.         {
    24.             float _speedboost = 1.0f;
    25.             if (_speedBoostActive == true)
    26.             {
    27.                 _speedboost = 1.5f;
    28.             }
    29.  
    30.             if (Input.GetKey(KeyCode.Keypad8))
    31.             {
    32.                 transform.Translate(Vector3.up * _speed * _speedboost * Time.deltaTime);
    33.             }
    34.  
    35.             else if (Input.GetKey(KeyCode.Keypad5))
    36.             {
    37.                 transform.Translate(Vector3.down * _speed * _speedboost * Time.deltaTime);
    38.             }
    39.  
    40.             if (Input.GetKey(KeyCode.Keypad4))
    41.             {
    42.                 transform.Translate(Vector3.left * _speed * _speedboost * Time.deltaTime);
    43.             }
    44.  
    45.             else if (Input.GetKey(KeyCode.Keypad6))
    46.             {
    47.                 transform.Translate(Vector3.right * _speed * _speedboost * Time.deltaTime);
    48.             }
    49.                                
    50.         }
    51.  
    52.         transform.position = new Vector3(transform.position.x, Mathf.Clamp(transform.position.y, -3.9f, 0), 0);
    53.  
    54.  
    55.         if (transform.position.x > 9.6f)
    56.         {
    57.             transform.position = new Vector3(-9.6f, transform.position.y, 0);
    58.         }
    59.         else if (transform.position.x < -9.6f)
    60.         {
    61.             transform.position = new Vector3(9.6f, transform.position.y, 0);
    62.         }
    63.  
    64.     }
     
  2. tv_Never

    tv_Never

    Joined:
    Nov 11, 2021
    Posts:
    11
    I can only assume the is that you are doing

    (_speed * 1.5f) for player one

    and

    _speed * _speedboost

    Player one could be calculating (_speed * 1.5f) before Time.deltaTime
    Whereas player two could be calculating _speedboost * Time.deltaTime first and then * _speed

    I could be wrong
     
  3. AnnieAlves

    AnnieAlves

    Joined:
    Jan 10, 2023
    Posts:
    4
    No, they are at the same spped, but what happens is that player one seems to need to aceelerate to get to that speed