Wheel colliders and continuous ground hit

Hello,
I have posted on Unity answers a few days ago, but I think it got lost in the sea of other questions, so I thought of moving my questions to the forum. I hope it is okay (original: https://answers.unity.com/questions/1800212/wheel-colliders-and-continuous-ground-hit.html).

I have a problem with continuously detecting a ground hit from a wheel collider. I am creating splashing effects where a car drives into a puddle and the water stirs up (using the custom render texture, I am drawing a point where the car hits the texture and using a wave equation I spread it into a ripple).

When the car drives slowly the wave follows where the tire has been, however, when the car drives fast enough, artefacts start to appear - the ground hit is not continuous, leaving a few ripples here and there which is not what I want.

Is there a way to deal with this? Right now I am drawing a line between two hit points, but I would like to know if there is a better solution.

The shortened code:

     void Update()
     {
         if (wheelCollider.GetGroundHit(out WheelHit hit))
         {
             //contact point is created if wheel hits the road
             if (hit.collider.gameObject.layer == roadLayer)
             {
                 Vector3 hitPoint = hit.point + (car.velocity * (Time.deltaTime));
                 //... create ripple at this position...
             }
         }
     }

There’s no continuity in the WheelCollider collisions. Every physics update the wheels cast a ray, and that single collision is used to compute the wheel physics. The result of that raycast is provided in the GetGroundHit call. The WheelHit info gets updated values on each FixedUpdate only. Calling GetGroundHit from Update will likely receive duplicated values when Update is called several times between each FixedUpdate.

So basically you have to implement the continuity yourself. Take the updated values at FixedUpdate, then interpolate/extrapolate them in the next Update cycles to get a continuous sequence of points.

1 Like

Thank you for your feedback, it is sort of what I am doing right now :slight_smile: