- Home /
How to make a custom wheel collider ?
This is something i'm trying to get to grips with although at the moment I have no real reference on how to go about it. I pretty much need the standard unity wheel collider however instead of the usual raycast replaced by a sphere cast in its place. This will enable full surface collision with the wheel instead of the normal issues facing standard wheel colliders not working for wheelies or colliding properly with the environment. Question is do I have to re write an entire new wheel collider system or is it possible to modify the existing system making use of the Physics.SphereCast function ?
You can't do it with a spherecast, it doesn't have enough information. What you could to is multiple raycasts, which should work :)
Nope I was wrong, spherecasts to give enough information. I suggest you study rigidbody dynamics and with that, learn how to implement your own wheel collider :)
I know people who have got sphere casts to work but as of yet not figured out how to get them working myself, i'm not a hardcare coder so could really use some help with this if anybody can please pitch in :)
Answer by Scribe · Jun 10, 2013 at 12:24 PM
I hadn't noticed how old the question was until after I commented, it appears someone else wanted it reawakened!
Anyway, attaching a script like the one below to your wheel object will create a collider for it though it won't have all the variables that a wheel collider exposes so you may have to code those yourself.
private var col : MeshCollider;
function Start () {
col = gameObject.AddComponent(MeshCollider);
col.isTrigger = false;
col.sharedMesh = gameObject.GetComponent(MeshFilter).mesh;
col.convex = true;
}
Personally I think your implementation of the sphere collider looks pretty good but maybe you will have problems if you want the bike to fall over.
Not sure if this will help, good luck!
Scribe
It's a Q/A site. It doesn't matter if a question is old. A ton of people come here to the unity Q/A and find questions without answers. I know your Answer is 3 years old but since your still active I thought I comment.
Your answer
Follow this Question
Related Questions
Raycast exit point of collider 0 Answers
Raycasting doesn't hit terrains 0 Answers
Upper limits of Raycasting; Physics engine "gives up" 0 Answers
What's wrong with my RayCastHit2D? 0 Answers
Raycast origin overlapping surface of collider counts as a hit 0 Answers