Racing Car Game # Day 3 — Steering

In the previous article, Racing Car Game # Day 2 — Rotate Wheel Mesh, we synced the wheel mesh position and rotation with that of its parented wheel collider. In this article, we will go a little further by adding front wheel steering.

Since this vehicle is a front-wheel drive, we need to make sure the first two colliders in the array are the front wheels. Click on the Car and use the Inspector to confirm.

Before we go making any changes, let’s take a moment to understand how this steering works. If you look closely at the Wheel Collider, there is a small sphere at the bottom which represents where the forces will be applied when steering the Wheel Collider.

In the Locomotion script, add a variable to store the maximum steering angle

In the Update method, capture the left and right inputs and pass them in the Move call. Modify the Move method to include the steering parameter.

Inside the Move method, since we are only applying a steering force to the front wheels, we will only look at the first two, hence why we needed to make sure the front wheels were the first two in the array.

First, we clamp the steering input values and multiply them to the maximum steering angle.

Then apply it to the first two wheels

That’s it. Save the script, head back to the Editor, and press Play. We now have steering working.

In the next article, we will be adding braking, skid marks, and skidding sound effects to the vehicle.

If you enjoyed reading this article give me a Clap, also if you would like to see more, “Follow” me, so you may be notified of future releases. You may also send me a message if you need any help or if there is something you think I can improve.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store