Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Wheel colliders and continuous ground hit

Discussion in 'Physics' started by shanataru, Jan 3, 2021.

  1. shanataru

    shanataru

    Joined:
    Mar 4, 2019
    Posts:
    13
    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:

    Code (CSharp):
    1.      void Update()
    2.      {
    3.          if (wheelCollider.GetGroundHit(out WheelHit hit))
    4.          {
    5.              //contact point is created if wheel hits the road
    6.              if (hit.collider.gameObject.layer == roadLayer)
    7.              {
    8.                  Vector3 hitPoint = hit.point + (car.velocity * (Time.deltaTime));
    9.                  //... create ripple at this position...
    10.              }
    11.          }
    12.      }
     
    Last edited: Jan 3, 2021
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,497
    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.
     
    shanataru likes this.
  3. shanataru

    shanataru

    Joined:
    Mar 4, 2019
    Posts:
    13

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