# Question Why there is gameplay difference between those inputs?

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

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.
31.             {
32.                 transform.Translate(Vector3.up * _speed * _speedboost * Time.deltaTime);
33.             }
34.
36.             {
37.                 transform.Translate(Vector3.down * _speed * _speedboost * Time.deltaTime);
38.             }
39.
41.             {
42.                 transform.Translate(Vector3.left * _speed * _speedboost * Time.deltaTime);
43.             }
44.
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

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