UnitySkidmarks: Free skidmark generation system

Skidmark generator scripts in Unity that I’ve found in the past either seem to have bad performance, or they’re trail renderers where the whole thing disappears as soon as the car stops skidding.

I’ve made one that’s kind of based on the really old official car tutorial’s one, but instead of insane garbage generation that uses up quarter of your CPU in a frame every half second, it generates no garbage. Performance is good unless you’re doing something insane.

Do what you want with this: GitHub - Nition/UnitySkidmarks: A simple skidmark effect generator for Unity3D

Update in 2021: Please note that as of 2021 this project still works, and feel free to use it, but I won’t be maintaining it or providing support for it any longer.

6 Likes

is this works as 2D TopDown?

I’ve never actually used the 2D side of Unity. If it’s just basically a camera looking straight down it should work. You control when and where the skidmarks generate, and they’re just a mesh.

1 Like

Hi, your script works great except one thing, marks are placed even during normal turning, do you know how to fix this?

Edit: The previous post has been edited, and I was replying here to it originally reading: “Hi, your script works great except one thing, marks are under terrain and distant.”

Hmm, I use the same script on Unity terrain with no trouble, but I haven’t tested it in recent Unity versions. Does it look correct if you run the Sample Scene?

No, in Sample Scene the same situation, slow speed, no acceleration, and marks during car turn. You can see video when Google will finish processing https://drive.google.com/file/d/13tw8d_qri66gyseqpMlZTi0BcYzlucgX/view?usp=sharing

It looks like you’re holding the handbrake on those turns? Or maybe wheel physics have changed a little in the latest Unity versions. The physics on that car are pretty bad anyway honestly - it’s a default Unity sample car. I wouldn’t recommend using it in a proper game, it’s just in there to show how the skidmarks work.

Re skidmarks on turns. Check out WheelSkid.cs in the project. It’s pretty simple and commented. Note how the skidTotal is calculated as a sum of the sideways slip (car not going the way it’s facing) and wheel spin (loss of traction). You could remove or modify the sideways slip calculation if you like.

@Wenon , have a look at this line:

// NOTE: This extra line should not be needed and you can take it out if you have decent wheel physics
// The built-in Unity demo car is actually skidding its wheels the ENTIRE time you're accelerating,
// so this fades out the wheelspin-based skid as speed increases to make it look almost OK
wheelSpin = Mathf.Max(0, wheelSpin * (10 - carForwardVel));
1 Like

Thanks Deeeds, I forgot about that line! That just goes to show how bad the default vehicle actually is.

1 Like

Thank you, much better when I changed 10 to 0

1 Like

@Wenon I’m really glad you’re able to discern which way to move which number. I didn’t have a clue. My math skills are in minus territory. I was purely entertained (and drawn to this line) by the fact it’s not necessary and so pointedly/humorously commented. I didn’t even dare suggest which part of it to try changing to get a desired result. It’s Egyptian hieroglyphics, to me.

@Nition you deserve an award for figuring out the problems and how to solve them. I have been completely mystified by the Wheel Collider. It seems like a bad idea, badly designed and badly implemented.

1 Like

Maths is one thing, but don’t ever feel bad that you can’t get the wheel colliders to work - they’ve been almost unusable since the PhysX update in Unity 5.0. You’re either sliding on ice or jittering off into space with anything but the most generic vehicle.

In case you’re even thinking of feeling bad that you can’t get the wheel collider to work for you, consider that:

  • The official example vehicle is constantly losing traction when accelerating at any speed. Unity Technologies themselves couldn’t make it work right.
  • Even Edy, the creator of the most popular vehicle package on the Asset store, couldn’t get them to work without disabling most of what they usually do. [(source)]( Unity 5. WheelCollider component is unusable. page-6#post-2077136)

Funnily enough the Unity 4 version of the wheel colliders was actually not bad.

1 Like

Great Job Nition! It’s almost a drop in replacement for Realistic Car Controller’s SkidMark system - except now rather than 190KB of GC every frame (lots of vehicles), I’m now getting 0B… Thanks!

3 Likes

Thanks. :slight_smile:

I haven’t used Realistic Car Controller but I bet theirs is based on the insane garbage generating one from the old Unity 3 Car Tutorial.

1 Like

Thanks for sharing this script. I’ve got a small problem with using it. The side marks are way off the position that should be.

Vector3 localVelocity = transform.InverseTransformDirection(m_Rigidbody.velocity);
                float skidTotal = Mathf.Abs(localVelocity.x);

                float wheelAngularVelocity = m_WheelColliders[i].radius * ((2 * Mathf.PI * m_WheelColliders[i].rpm) / 60);
                float carForwardVel = Vector3.Dot(m_Rigidbody.velocity, transform.forward);
                float wheelSpin = Mathf.Abs(carForwardVel - wheelAngularVelocity) * WHEEL_SLIP_MULTIPLIER;

                // NOTE: This extra line should not be needed and you can take it out if you have decent wheel physics
                // The built-in Unity demo car is actually skidding its wheels the ENTIRE time you're accelerating,
                // so this fades out the wheelspin-based skid as speed increases to make it look almost OK
                wheelSpin = Mathf.Max(0, wheelSpin * (0 - carForwardVel));

                skidTotal += wheelSpin;

                if (skidTotal >= SKID_FX_SPEED)
                {
                    float intensity = Mathf.Clamp01(skidTotal / MAX_SKID_INTENSITY);

                    Vector3 skidPoint = wheelHit.point + (m_Rigidbody.velocity * (Time.time - lastFixedUpdateTime));
                    lastSkid = skidmarksController.AddSkidMark(skidPoint, wheelHit.normal, 1, lastSkid);
                }
                else
                {
                    lastSkid = -1;
                }

This is my code for creating them. Any ideas?

That code you pasted is just part of WheelSkid.cs that comes with the project. Do the skidmarks show in the right place when you’re running the default test scene that comes with it, before you’ve made any changes?

Check where your wheelHit.point actually is - does it match your wheel positions?

Try removing the velocity component, just setting skidPoint = wheelHit.point, and see where it ends up then.

wheelHit.point is in good position.
I’ve removed the velocity component and there is no changes.
Test scene was working fine.

Okay, I’m out of ideas then I’m afraid - something’s different between yours and the original test scene. Maybe post here if you manage to work it out, just in case others have the same issue in the future.

ok, i’m stupid. Object with skidmarks controller was not on position 0 0 0 but 21 -8 0…

Ah, that’s not that stupid, I should be allowing for that or at least putting in a note that it needs to be at 0,0,0. Thanks for bringing it up. I think Wenon earlier in this thread probably had the same issue when they said "your script works great except one thing, marks are under terrain and distant", but they edited their post to something else after fixing it.