- Home /
Horizontal Input
I was told that Input.GetAxis is more efficient than Input.GetKeyDown(KeyCode.W A S D).
as it can also be used on controllers
How do I detect which direction the horizontal axis is facing? Like is there a value of how "hard" it is moving in that direction? If so what is it called?
sorry for being stupid
Answer by smpark12 · Jun 25, 2019 at 11:05 PM
I currently have if (Input.GetAxis ("Horizontal") > 0.1) { GetComponent().velocity.x = (1); } if (Input.GetAxis ("Horizontal") < -0.1) { GetComponent().velocity.x = (-1); } but that sort of defeats the whole purpose of it as it is either moving left or right, nowhere in between.
public float range;
void Update()
{
float h = Input.GetAxis("Horizontal");
float xPos = h * range;
transform.position = new Vector3(xPos, 0f, 0f);
}
check this out
thanks! I suspected that it returned some sort of value but I didn't know how to implement it
Your answer
![](https://koobas.hobune.stream/wayback/20220612203845im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
PS4 Controller Y-axis is linked to L2-button? 0 Answers
Creating custom input actions 1 Answer
Platform dependent control schemes 0 Answers
How to assign the right inputs to the right clone? 1 Answer
Horizontal as a NGUI button 0 Answers