How WheelCollider's raycast stop rigidbody falling?

Hello everyone!

I need some help or hint about the question in the title. Well, I want to work on a racing game. An arcade one, with scripted physics, I don’t want to use built-in wheel colliders. I just realised it makes the whole thing hard for me. I started my project based on James Arndt mobile car physics. This one if you interested in it: http://youtu.be/amsUjRLMuDc?t=2s

Well, I really like, how it works, except the collision detection. I realised, I need something like wheel collider but without friction curves. I need just simple suspension. So I would like to make my own raycast based, simple suspension. I just don’t understand, how can I make the raycast act like a collider. So, at the raycast hit point, how can I stop my car rigidbody? Making the whole thing working as a suspension with springs is an other topic, hopefully I’ll figure it out on my own.

My hierarchical setup would be like this:

CarObject
-CarModelObject
–SomeSubMeshes
-MyCustomWheelColliders
–FR
–FL
–RR
–RL
-OtherStuffs.

Not sure what you exactly want, but couldn’t you just set the wheels.transform.position.y to the hit.point.y? That way the wheels are always hitting the ground while that car body follows a different y.

Yes, I can set the wheel meshes position to hit point.y+wheelradius that’s what I want for visualize the wheels! But it just position the wheels, not the car itself. I don’t understand, how the wheelcollider does what it does. Or does it use fixed joint? I don’t think so, but…

Simply explained, I want to create a wheel collider that only has suspension and raycast based collision. I don’t want forward and sideway friction, that will be coded in a much simpler way that I can take control over, if I want simpler than in case of Unity’s wheel collider component by applying forces if I want to simulate slippery and other things.

One way you could do something similar is to create Sphere Colliders at your wheel positions that are parented to the rigid body. These sphere colliders along with the car’s main body collider then form a compound collider that stops your car falling through the track. Raycasts can still be used to detect the distance from the wheel center to the ground so you can for example, expand and compress the suspension (basically moving your sphere colliders along the ray).

In many ways this will be preferable to your Ray only approach as you wont have the problem with the wheel collision contact points being a single point on the road surface. That is, it will more correctly model your car driving object little bumps or debris in the road.

There is a wheel collider source implementation on the Unity Wiki and if I recall correctly sphere colliders are used there too. It comes with source code so will help you understand how they work.

http://wiki.unity3d.com/index.php/WheelColliderSource

Hope that helps

Thanks man, it actually looks helpful! I’ll write here, what I could achieve. So I’ll try the raycast+sphere collider combo.