Search Unity

WheelCollider + NavMesh Integration

Discussion in 'Scripting' started by cl9-2, Jul 25, 2014.

  1. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
    Has anyone successfully integrated WheelCollider + NavMesh support into their projects? I'm looking into different approaches for vehicle AI, specifically arcade racing.

    Thank you
     
  2. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    I think that NavMesh might not be the best solution for a racing game, especially if it's just a fixed track.

    Have you considered just placing 'waypoint' markers around the track pointing in the direction needed, if they are fitted with offset trigger volumes then as the cars move around the track they read the new heading and can adjust their steering to match. With midline, outer and inner markers cars on the outside/inside would receive headings attempting to get them back on track.

    Also if the waypoints have an ideal speed then the cars can accelerate and decelerate.

    Would be fiddly to setup and get right but you could setup a recorder where you drive a car around and the track records your speed and heading in the markers.

    Or you could set up a self learning version that runs AI cars around the track at accelerated randomised speeds until failure points are reached then adjusts the waypoint settings.
     
    ZiadJ likes this.
  3. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
    I've tried the waypoint navigation approach, but encountered problems with enemy vehicle and obstacle avoidance. I was hoping that Unity's Navmesh could work with vehicles so that I could use the obstacle avoidance.
     
  4. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    You could have each vehicle do a raycast or three ahead of them then adjust their steering depending on velocity differences.
     
  5. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
    The main problem I've encountered with this ray cast approach is cars running into obstacles and walls in trying to avoid other cars. Even if the edges of the track are treated as obstacles the car will go into a rapid cycle of approaching the edge, then suddenly steering away from the edge.
     
  6. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    So you need your AI to detect the difference between another car and a barrier. They can also apply the break to prevent impacting another car.