- Home /
How to make a car move forward indefinitly ?
I made a car controller and it works, the car moves. but the problem is that it needs input to move forward. But in the game that i'm making, it has to go forward constantly. And input will be used to go left, right and backwards. How to i make it go constantly forward ? Here is the input part of my code.
private void GetInputs()
{
inputX = Input.GetAxis("Horizontal");
inputY = Input.GetAxis("Vertical");
}
Answer by hacky97 · Jul 09, 2020 at 02:28 PM
Inputs have a value between -1 and 1, where 0 is center. You want the center of the stick to be tied to forward, So I would multiply the value by 2:
inputY = Mathf.Min(Input.GetAxis("Vertical") * 2 + 1 , 1);
This will make the stick essentially stay stuck in forward position when released and go in backward when held back.
Answer by HexStudio · Jul 10, 2020 at 06:52 PM
Thank you. But i want the car to go backwards when i press S or Down. How can i do it ?
If I am correct, that is what will happen. The car will automatically accelerate. When the stick is pressed halfway down, the car will stop, when pressed fully down, the car will go backwards.