Skip to content

RehmanLn1/Unity-3D-Car-Controller

Repository files navigation

Unity 3D Car Controller 🚗

A simple and reusable 4-wheel car controller for Unity written in C#. This script allows any car with separate wheel meshes and WheelColliders to move, steer, and brake using keyboard input.

The controller is designed to be lightweight, easy to understand, and easy to integrate into any Unity car project.


✨ Features

  • Simple 4-wheel vehicle controller
  • Uses Unity WheelColliders
  • Works with separate tire meshes
  • Smooth steering and acceleration
  • Brake system using Space key
  • Automatic wheel mesh synchronization with colliders
  • Easy to attach to any car model

🎮 Controls

Key Action
↑ Arrow Move Forward
↓ Arrow Move Backward
← Arrow Steer Left
→ Arrow Steer Right
Space Brake

🧩 Requirements

  • Unity 3D
  • A car model with 4 separate wheel meshes
  • WheelCollider for each wheel

⚙️ Setup Instructions

  1. Import your car model into Unity.

  2. Create 4 WheelColliders:

    • Front Left
    • Front Right
    • Rear Left
    • Rear Right
  3. Ensure each wheel has a separate mesh object.

  4. Attach the CarController.cs script to the main car GameObject.

  5. Assign the following in the Inspector:

    • WheelColliders
    • Wheel mesh transforms
  6. Adjust settings like:

    • Motor Power
    • Braking Power
    • Max Steering Angle

📂 Script Overview

The controller handles:

  • User Input
  • Motor Torque
  • Steering
  • Braking
  • Wheel Mesh Updates

It synchronizes WheelCollider physics with the visual wheel meshes to keep them aligned during movement.


🚀 How It Works

The script performs these main tasks every physics frame:

  1. Reads player input (arrow keys + brake)
  2. Applies motor torque to the front wheels
  3. Applies steering angle
  4. Applies brake torque
  5. Updates the wheel mesh position and rotation

🧠 Customization

You can easily modify:

  • Top speed (via motorPower)
  • Turning sensitivity (via maxSteeringAngle)
  • Brake strength (via brakingPower)

📜 License

Free to use for learning and personal projects.


👨‍💻 Author

Created by RehmanLn1

About

Lightweight Unity C# car controller that works with any 4-wheel vehicle model using WheelColliders and separate tire meshes. Includes steering, acceleration, reverse, and braking controls.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors