Basic Car Movement with New Input System Unity

Prasetio Nugroho
3 min readApr 1, 2023

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.

Input system Concept (https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/manual/Concepts.html)

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.

Main scene with car assets

Then install Input System Package

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.

car basic movement input actions

Then, generate C# Class, tick the checkbox.

generate C# Class

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.

input system log console

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.

rigidbody and box collider setup
wheel collider setup

Press play to make sure the physics correct, it should be fall and idle.

correct physics setup

Add function to move the car.

car movement

Add function to turn

moving with 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.

setup wheel mesh

And here is the result

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.

Resources

  1. Unity Input System ~ https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/manual/index.html
  2. 3D Retro Car ~ https://assetstore.unity.com/packages/3d/vehicles/land/retro-cartoon-cars-cicada-96158

--

--

Prasetio Nugroho

Interested in new tech, gaming, programming and another knowledge or possibilites that can make me better. Cheers!!