🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Simple ray-cast vehicle

Started by
1 comment, last by Edy 6 years, 2 months ago

Hi guys, 

I want to write a really basic raycast vehicle(a car with 4 wheel that can steer). I tried to come up with the math's myself, but the result isn't good the car isn't stable, and oscillates up an down?
Do you know any good tutorial on how to do it?

Currently I do a raycast, and if the distances is lower than the distance my tire what's to be I apply this force (which really doesn't work):
forcePerTire = RaycastDir * (hitDistance / IdealTireDistance) * forceMultiplier;

I guess this is more a hoverboard, not a car,
 

Advertisement

You have to add some damping to the suspension, otherwise it would hardly stop oscillating. A basic suspension could be implemented like this (pseudocode):


contactDepth = maxHitDistance - hitDistance;
contactSpeed = (lastContactDepth - contactDepth) / deltaTime;
lastContactDepth = contactDepth;

springForce = contactDepth * springRate;
damperForce = contactSpeed * damperRate;

forcePerTire = RaycastDir * (springForce + damperForce);

You would then configure the suspension with the springRate and damperRate parameters.

This topic is closed to new replies.

Advertisement