This is a full Manual and Documentation for the Unity Any Car AI. It will cover all features, uses and set up procedures.

Set Up

Set up a car Artificial Intelligence in Unity as never been so simple and quick and it literally takes 1 minute.

The script is adaptable to any car model. Only necessary requirement is that the wheels must be separated objects from the car body and their pivot point must be on the relative wheel position.

Also if you want to use the Damage System, make sure you tick the Read/Write Enabled Check on the model. Theat will allow you to Deform the mesh.

  • Drag and Drop the AnyCarAI Prefab into your Scene.
  • Drag and Drop your car model as a children of the “ModelParent” object in the Hierarchy.
  • Drag and Drop references of wheels and body into the appropriate fields of the AnyCarAI component into the AIScript game object.
  • If your vehicle has more than 4 wheels add the number of the extra wheels you need into ExtraWheels > Size.
  • Drag and Drop the references for your extra wheels models and select whether you want the wheel to be front(steering wheel).
  • A consistent car body model is necessary to keep the wheels together and avoid bugs. In case you do not have that on your model PRESS the “CreateBodyCollider” Debug button and it will create a car body template.
  • Press “Attach Script” to complete set up.
  • Drag and Drop the Path Prefab into your scene and move or add nodes in order to create the path for you car and make a refercence on the AI Tab under AI Target
  • Don’t forget to adjust the position of Sensors in order to have the necessary driveability

Wheels

The wheels attributes determine the actual physics of the wheels and suspensions of the car.

Wheel Stiffness: Changes the stiffness of the friction. Setting this to zero will completely disable all friction from the wheel. Usually you modify stiffness at runtime to simulate various ground materials from scripting.

Dumping Rate: This is a value of damping applied to a wheel.

Suspension Distance: Maximum extension distance of wheel suspension, measured in local space. Suspension always extends downwards through the local Y-axis.

Suspension Spring: A larger value makes the suspension reach the Target Position faster.

Suspension Dumper: Dampens the suspension velocity. A larger value makes the Suspension Spring move slower.

 

Vehicle Mass: It controls the actual weight of the vehicle.

 

The Steering Values will adjust those parameters that are relative to your steering commands.

Turn Sensitivity: Decimal Values will decrese steering sensitivity, values greater than 1 will increase it.

Max Steer Angle: Steering angle in degrees.

 

The debug section is really only used for particular situations where the car model has no consistent pivot point and object structure and using this values you can put every bit back in the right position.

Wheel Position: It is a Vector3 Value and it determines the position of the actual wheel.

Wheel Rotation: It is a Quaterion Value and it is used in case the pivot points of your car models do not respect the directionality of the rest of the car. This can cause some strange behaviour of the wheels on runtime. This value is used to adjust this behaviour.

 

During the first setup step, pressing the “Attach Script” button you create wheel objects with wheel collider components on it.

With these values you can bulk control the main values of those wheel colliders that you created.

For more advanced options you can just go and change the values directly on the actual wheel collider components.

 

Artificial Intelligence

Control your car on the AI Tab in order to customize your car behaviour.

AI Target: Make a reference of the path prefab that you are using in order to control which main path the car is following.

Waypoint Distance: Here select how close your car need to drive to each point to step onto the next node of your path.

Acceleration: Set here acceleration for your car. Values really depends on size and mass of your car. Adjust accordingly.

Max Speed: This value will determine the maximum speed that the car can reach. Once it reaches it, the car will keep its speed still.

Brake Force: That will determine the strenght of your brakes.

Brakes Distance: Here select how close your car need to drive to an Obstacle in order to brake.

Reverse Distance: Here select how close your car need to drive to an Obstacle in order to use Reverse Gear.

Engine Sound: Insert .mp3 or .wav files here. Here you need to insert an engine idle sound in order to simulate different types of engines. AnyCarController provides sounds for diesel, turbo and electric engines. You can use your own sound if you want to simulate a particular kind of engine.

Sensor Angle: That will deteremine the angle of your side sensors. It is measured in degrees.

Sensor Lenght: It determine how close to an obstacle your car needs to be to calculate a new path.

Turn Speed: Determine how fast the steering is applied (Humans are slower than computers, it makes the driving look more natural.

Features

Use the Features Tab to customize the details and aesthetics of your car .

Front Lights ON: Check this option if you want to use the front lights.

ABS Check: This option will activate the Anti Brake-locking System.

Collision System: Check Collision System if you want some kind of collision effect.

In order to deform your car model on collision make sure the model Read/Write Enabled Option is checked. Set Demolution Strenght Value based on how much you want your car to be damaged on collision.

Use Collision Sound to simulate collisions. You can use .mp3 or .wav files.

Use Optional Mesh List Array is you only want some mesh to be damaged.

Persuit Target: Check this option if you want the artificial intelligence to follow a moving gameObject. Use Persuit Target to make reference of the object and Set Persuit Distance to determine how close your artificial intelligence need to go in order to leave its path and follow the persuit target.

Skid Marks Check: This option will activate skid marks sound, marks renders and smoke on the floor when the wheels friction become particularly high. It is possible to use custom materials for the skid marks renders.

In the advance section it is possible to change advance parameters for the car.

Center of Mass: It is a Vector3 value and it represent the point of maximum weight. It is often used to give the car more balance on steering.

Gear Ratios: The first value determine how many gear your car will have. Any Car Controller set as default the gear ratios of an avarage BMW. Here you can use custom values and configurations. 

Prefab

The AnyCar AI Prefab contains two main sections.

In the utility you will find gameObject that assist the AI.

During the set up the important thing to know is what to do with the AIScript and its content.

A part from configurations explained in the previous section you might need to know how to deal with the Utility Content.

Infact there you can find:

  • Sensors: Place Sensors relatively to your car model size and the type of path that is following.
  • BackLights: This GameObject contains the red backlights of your car that light up everytime you use brakes. Position these objects in place relatively to your car model.
  • Front Lights: This GameObject contains the white position front lights. Position these objects in place relatively to your car model.

Hope you enjoyed. Feel free to contact me if you have any question, request or doubt.

Thanks for your attention on Any Car AI for Unity.

— BoolBird —