Skid Marks Code Design / Structure

Has anyone figured out a way to make realistic skid marks based on the friction of the wheels of cars? I’m trying to make a script that makes the car wipe out if the wheels lose traction. I also only want skid marks if the wheel is actually sliding. I don’t think there’s any way to check how much frictional force is actually acting on a part at a given moment, so if anyone’s found an alternative I’m all ears :slight_smile: Thanks!
-big

Note: if you can’t post to devforums, PM me.

3 Likes

There is actually a way to calculate the skid of the car: The only force acting on the car is the tires, so as long as it doesn’t hit anything, by tracking the position / rotation of the car and calculating the force needed to accelerate it the way it is accelerating, you can figure out not just an approximation, but exactly how much force the tires are exerting and whether there is any slippage (at least down to the granularity of the physics simulation).

Doing that exact calculation is fairly difficult, but you could do a rudimentary one pretty easily (Just calculate the magnitude of the car’s acceleration and assuming that when it spikes very large then it must have hit something and the acceleration isn’t from the tires)

If your car is entirely physical and you actually want to calculate when the wheels are actually slipping then you would have to do the full harder calculation though (knowing the width of the car / tires, the rotational velocity of the tires, the linear and angular acceleration of the car, etc) It gets decently complicated and you would probably want someone who has taken a university level mechanics course to solve it for you.

3 Likes

local skid = math.abs(engine.CFrame.lookVector:Dot(engine.Velocity.unit))

will give you a number on how much the car skids.

  • 0 = Completely skids - it’s going sideways 100%.
  • 1 = No skidding - it’s going straight forward.

When skid > 0.3 or something, enable the trail.
Should be fast and quite reliable.

11 Likes

The only problem with using a trail is if the car gets off the ground, it’ll place the trail into the sky, which looks rather strange.

Small Video Showing What Your Suggestion Looks Like

https://media.giphy.com/media/l3diSa44d2oreP6Jq/giphy.mp4

Couldn’t you use raycasting to solve that problem?

Yea but even if you use another solution you’ll eventually need to raycast to make sure the car is on the ground.
I’d suggest a single raycast from center of the car every .2 seconds.

I’ve done this. Check if it’s sliding or drifting, and if it is then raycast from the center of each tire to .2 studs below the tire. If the ray hits pavement then activate the skid. If one is touching the pavement it will make a skidmark, independent of the other tires. If one is in the air it will not make a mark.

1 Like

This wouldn’t make a skid appear if I apply the brakes hard while going in a straight line.

1 Like

True, for such skidmarks you need to custom enable the trail.

Assuming you’re not using high freq. ABS. In which case there are no skidmarks.

2 Likes

Your method doesn’t really work for me.

I have a wheel hub and a wheel (the front surface of the hub highlighted):

My skid calculation is this:

local skid = 1 - math.abs(hub.CFrame.LookVector:Dot(wheel.Velocity.Unit))

But skid gets really weird and keeps giving me stuff like this while the car is going exactly straight:

FR skidding! (0.96256842464209)
BR skidding! (0.38571208715439)
BL skidding! (0.063570141792297)
FL skidding! (0.47344994544983)

0 is no skid, and 1 is skid here.

1 Like