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:
https://www.youtube.com/watch?v=CdPYlj5uZeI

1 Like

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

can you please help me how to use this ?
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:
https://forum.unity.com/threads/please-someone-help-me-understand-joints.1507667/#post-9419714
There's a great video here that demonstrates possible problems with raycasts:

https://www.youtube.com/watch?v=T8MB1Txi2-I

I'm not sure I feel like there's a "best" approach. I feel like raycasts would be awkward for the kind of vehicle/terrain behavior I'm trying to implement; but for other stuff I guess they're fine.
Unless you're very maths&physicsy, or trying to learn because you want to, I'd definitely recommend letting an off-the-shelf solution do most of the work for you. I really like Edy's vehicle physics stuff, except that it's raycast-based (which is only a problem for my very specific requirements) (Edy's currently working on ditching the unity WheelCollider though, so I'm pretty excited:).
I'm always delighted by this ultra-simple approach:
https://twitter.com/KenneyNL/status/1107783904784715788?lang=en
:)