Basic Car Movement with New Input System Unity
As we know, unity has new input system some years ago. Technically it change the way of thinking to use input system in unity. Like in unity input system documentation, basically we create a binding based on platform with same output action.
Let’s start to try new input system and integrate with basic car movement.
Preparation
I am using new URP Project Template then import free 3d car from asset store.
Then install Input System Package
Create New Binding in Input System
Create new Input Actions with Assets -> Create -> Input Actions. Then it will created a asset file. Open it to check. There will be default Actions created, move, look and fire. Just leave it like that.
Then, generate C# Class, tick the checkbox.
Create script and attach to empty gameobject. The script has function to control the car with input system but test the input first, log in console to make sure input is correct.
Press Play Button, press WASD input and check the log. The result should be like image below.
Car Movement
After success connect the input, create function to move the car. But we should setup wheel collider, box collider and rigidbody for physics. Setup rigidbody mass into 1000.
Press play to make sure the physics correct, it should be fall and idle.
Add function to move the car.
Add function to turn
The movement is done but the wheel still wrong. Create a function to attach wheel mesh position and rotation into wheel collider.
Setup wheel mesh in inspector.
And here is the result
Conclusion
With new unity input system, you can create 1 action with multiple compability input from different platform. You can check github repo for this project.