# Making a car WITHOUT wheel colliders

Hi, so I'm attempting to create a very simple rigidbody based car in unity, without the physx wheel colliders.

What I have right now, is a box with a collider and rigidbody, with 4 cylinder colliders as wheels. I simply use addforce to propel the car and that seems to work fine. Next, I added some raycasts to the base of the two front wheels, so that it can detect if there's an object in front of them, which tells the game to add some force upwards to the front of the car, to try to help it climb over whatever the obstacle is in front of it (assuming it isn't too high.)

Am I on the right track here?

Another thing I wanted to ask is, how do I get the wheels to rotate correctly? I definitely don't need this car to be super realistic by any means, but I at least want the wheels to rotate proportionally to the car. Is there some sort of formula someone can give me, that will rotate the wheels based on how fast the car is moving?

1 Like

Using cylinders for wheels is not a good idea unless it's strictly visual because the contacts will be very hit and miss for the desired behaviour. It's best to use raycasts / sweeps and maths.

[quote=â€śhippocoderâ€ť, post:2, topic: 845687]
Using cylinders for wheels is not a good idea unless itâ€™s strictly visual because the contacts will be very hit and miss for the desired behaviour. Itâ€™s best to use raycasts / sweeps and maths.
[/quote]
Unfortunately I donâ€™t know much math and Iâ€™m just looking for the easiest way to go about doing this. Do you have a barebones example using sweeps or raycasts?

Edit: Okay so I followed a simple tutorial on youtube with how to do raycasts and it works pretty good, however if force is applied to the side of the car, the car will float freely to the side, but I only want it to move in the direction of the wheels (forward or backwards). Hopefully someone is able to assist me with this.

Edit #2:

https://github.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/blob/master/Assets/Scripts/RaycastWheel.cs

I ended up using this script and it seemly works well with minor modifications, however if anyone has any other examples, please do post them, because thereâ€™s hardly anything on the internet. It would not only benefit me, but other people in the future looking to work on their own custom vehicles.

Using sphere colliders as wheels with zero friction works much better than mesh collider wheels. However, you still run into weird ghost collisions on uneven mesh terrain / roads etc. The best solution seams to be something like this simple raycast wheel, except switch it to sphere cast for a better approximation.

[quote=â€śallencook200â€ť, post:3, topic: 845687]
I ended up using this script and it seemly works well with minor modifications, however if anyone has any other examples, please do post them, because thereâ€™s hardly anything on the internet. It would not only benefit me, but other people in the future looking to work on their own custom vehicles.
[/quote]

This video is a rather good introduction:

1 Like

https://github.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/blob/master/Assets/Scripts/RaycastWheel.cs

and what object i need to give reference in graphics box with a Wheel or Car body and with rigidbody ?
and where to put this script in wheel or in car body ? pls help me.

(Mostly adding my context to the stuff said earlier, sorry johnsonrk)
I talked over here a bit about how I'm using PrismaticJoint springs, zero-friction mesh-colliders & contact modification wheels: