Skidmarks

Hey guys

I have made this skidmark proc animation that uses the trailrenderer. only problem is it does not take into account where it is to to render on. Ideally I would want it to only render on the road rather than any other terrain.

Anyone got any ideas?

See the images for further details

8641920--1162380--upload_2022-12-7_13-8-36.png

Also here is the code as it is now

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Effects : MonoBehaviour
{
    public TrailRenderer[] skidMarks;
    private bool skidMarksFlag;
    public Material lightSwitch;

    private void Update()
    {
        checksteer();
    }


    private void checksteer()
    {
        if (Mathf.Abs(Input.GetAxis("Vertical")) < 0.1f)
        {
            lightSwitch.EnableKeyword("_EMISSION");
        }
        else
        {
            lightSwitch.DisableKeyword("_EMISSION");
        }

        if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1f && Mathf.Abs(Input.GetAxis("Vertical")) > 0.1f)
        {
            startEmitter();
           
        }
        else
        {
           stopEmitter();
           
        }
    }

    private void startEmitter()
    {
        if (skidMarksFlag) return;
        foreach (TrailRenderer T in skidMarks)
        {
            T.emitting = true;
        }

        skidMarksFlag = true;

    }

    private void stopEmitter()
    {
        if (!skidMarksFlag) return;
        foreach (TrailRenderer T in skidMarks)
        {
            T.emitting = false;
        }

        skidMarksFlag = false;
    }
}

What you could try to do is check with a physics raycast downwards from the wheels and check what kind of surface you’re dealing with. If it isn’t something what you want disable the emitter.

1 Like