- Home /
How should I make a custom suspension system?
I would like to make my own suspension system. Basically, it would be a wheel collider without the friction curves. So a simplified wheel collider. Probably faster and I don't really want to mess with the friction curves, my game doesn't need it, I would program the car's handling on my own. Friction things just make it harder and really not needed for my arcade style physics I planned.
There are things that I already can't figure out. I guess I need to raycast downward to suspension distance + wheel radius. But how can I position the parent rigidbody based on the raycast hit point? So I need a way to stop the rigidbody falling at the hit point. How it's working with the original Wheel Collider component?
If I could do this, I should start to figure out the spring system. I have no idea about that too yet, but maybe I can figure it out.
Answer by Mewada-Neil · Apr 20, 2015 at 06:03 PM
I can help you with making the wheel to move as a wheel with wheel collider's suspension.
The below scipt is for each wheel.
public WheelCollider wc;
void FixedUpdate()
{
RaycastHit hit;
Vector3 wheelPosition;
if (Physics.Raycast(transform.position, -transform.up, out hit, wc.radius + wc.suspensionDistance))
{
wheelPosition = hit.point + wc.transform.up * wc.radius;
}
else
{
wheelPosition = wc.transform.position - wc.transform.up * wc.suspensionDistance;
}
transform.position = wheelPosition;
}