- Home /
The question is answered, right answer was accepted
Can I make my car move forward only and without inputs?
So the game that I am working on is basically just a car moving forward indefinitely and dodging obstacles. This is my current code, the car does automatically move forward without any inputs but is there anyway I can modify my current code to disable my 's' or down arrow key?
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Mathf.Min(Input.GetAxis("Vertical") * 2 + 1 , 1);
// Move the vehicle forward
transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
transform.Rotate(Vector3.up, Time.deltaTime * turnSpeed * horizontalInput);
Answer by qsp18 · Jan 21, 2021 at 02:03 PM
Instead of 'Input.GetAxis("Vertical")', you could use 'Mathf.Clamp(Input.GetAxis("Vertical"), 0, 1)'
Then it cannot go under 0.
or u write 'Mathf.Clamp(Input.GetAxis("Vertical"), 0.5, 1)'
Then it will go with half speed and will go full speed when arrowUp
@qsp18 thanks for the input this does disable my backwards movement. However, my car stops moving forward automatically now is there anyway for it to move forward without pressing 'w'?
Follow this Question
Related Questions
car and controller 1 Answer
Unity Bug when I press play 1 Answer
Car AI Help 0 Answers
Problem with Rotate() conditions 0 Answers
3d car left and right touch input 2 Answers