if (Input.GetKey(KeyCode.D)) rigid.velocity = new Vector2 (moveSpeed, rigid.velocity.y); if (Input.GetKey(KeyCode.A)) rigid.velocity = new Vector2 (-moveSpeed, rigid.velocity.y);
is there any difference between those two? is one better than the other?
Thanks.
The difference between the two is that Input.GetAxis(…) pretty much simulates the way thumb-sticks function. It will start at 0.0f and if for example you press the D key it will gradually increase from 0.0f to 1.0f and pressing the A key it will go from 0.0f to -1.0f. This will affect your movement by giving it a delay to build up to its max speed based on how long the key is held down, while using Input.GetKey() like in your second example will instantly cause your character to be at max speed when you press the desired movement key.
If you go to Edit → Project Settings → Input in the Unity Editor you can set up your own custom axis for your desired inputs. The default Unity “Horizontal” axis is set up so the negative button is the A key and positive button is the D key (and a few other alternative keys and the left joysticks x axis).
here is a useful link that does a better job explaining things than i just did
Thanks a bunch.
Aside from that, are there no more difference?
I’ve tried both method and the acceleration speed,is somewhat different, is barely noticeable.