Making it so that the car cannot steer when at rest

That’s a more realistic approach to the car’s behaviour. Just assign a variable to be zero when the vertical input is zero (which means the car is at rest) and assign it to be 1 in the else case. Then, multiply that variable to the steerAmount variable (along with all the other stuff that’s multiplied)

Screenshot 2022-08-06 104731


Very good solution! I also implemented this using the following code

       if(Input.GetAxis("Vertical") != 0){
1 Like

why not just multiplying it with moveAmount? For this approach you might want to set steerSpeed as 10000 and moveSpeed as 10, but it fixes the reverse problem. For example, without this when you go reverse and press left, you will actually turn right, but this approach fixes even that and also takes into account boost speed.

float steerAmount = Input.GetAxis("Horizontal") * steerSpeed * Time.deltaTime * moveAmount;


I just did an if statement whether or not the car is moving “vertically”

u miss the float a = 0 ; in ur code , and that will no worke

Quick tip:

Don’t compare floats to 0, that is, eventually, gonna cause issues. Floats tend not to be 0, they might be something like “0.00000012”.

Always compare to epsilon, Mathf.Epsilon, and don’t use the equal sign, use greater or less than. You can also use the round-to-int function, Mathf.RoundToInt, integer values are… well… integer, so they won’t have super tiny values that might cause unexpected behaviors.

Another way to solve this is by checking if the input is pressed instead of measuring speed, this solves the float issue.

Privacy & Terms