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

NavMesh - CAR AI - Working.. Just not realistically

Discussion in 'Scripting' started by Grieve_physics, Nov 5, 2013.

  1. Grieve_physics

    Grieve_physics

    Joined:
    Oct 25, 2012
    Posts:
    26
    Hi All,

    I have an issue with the navmesh and Car AI.

    Although the Navmesh works properly at low speeds. The car needs to be sped up to look more realistic.
    When the speed is increased, the car appears to be travelling to fast to turn (Physically and Visually) to follow the road properly. Instead it slams into the wall.

    I have recorded a 90Second Video to demonstrate the issue.

    http://youtu.be/PRq1wqnx0Gs

    If anybody has any recommendations on how to fix the issue, or suggestions I could try, your help would be greatly appreciated.

    Thankyou in advance.
     
  2. 3agle

    3agle

    Joined:
    Jul 9, 2012
    Posts:
    508
    Try tweaking the Angular Speed variable on the NavMeshAgent, I find that this needs to be quite high(500 for me) for the wandering people in my scenes to turn efficiently.

    This value would likely need to be affected by the forward speed the car is travelling (as a cars turning circle is larger at higher speeds).
    I haven't checked this since my bots all use a consistent Angular Speed, but it's the first thing I would check.
     
  3. Grieve_physics

    Grieve_physics

    Joined:
    Oct 25, 2012
    Posts:
    26
    Cheers 3agle,

    Unfortunately even ramping the angular speed up to 1,000,000 still had no effect. Just cant get it turn appropriately... I am thinking I might need to add multiple waypoints on top of the navmesh, rather than simple "Checkpoints"
     
  4. 3agle

    3agle

    Joined:
    Jul 9, 2012
    Posts:
    508
    It could be something to do with the geometry of the mesh used for the NavMesh, but I'd find that a bit odd.

    It's probably worth noting that even if this system did work correctly it isn't going to work very well in terms of cars following the racing line, the Agents aren't that clever.
    So it could be worth looking at something like this: http://www.red3d.com/cwr/steer/
    Or looking at existing racing AI assets to see how they have implemented their systems: http://proracingai.com/Racing+Line

    That doesn't solve the problem of the Agents not turning though, perhaps more waypoints may help smooth out the problem as you say.
     
  5. Grieve_physics

    Grieve_physics

    Joined:
    Oct 25, 2012
    Posts:
    26
    Thanks again, Unfortunately the multiple waypoints does improve the situation, but still has issues.
    If I could somehow figure out what the parameter is to reduce its velocity/force I would be all set... but no luck as the Unity Documentation is empty on the topic. :(
     
  6. Gaski

    Gaski

    Joined:
    Jul 25, 2011
    Posts:
    84
    Hi,

    I have actually completed a Racing Game for Unity about a year ago and imo using Unity's standard NavMesh/NavAgent stuff just isn't going to do it for you, not by a long shot. I had to write a completely custom system to control my AI cars. The problem is that the cars are going so fast - and can sometimes be quite tightly grouped in a small space - that your AI cars just need to know a lot more about the track ahead and the other AI cars around it.

    In my system I used race lines to pull a "Rabbit" around the track which the AI cars then tried to follow a closely as possible. The race line nodes also store lots of information about the track, things such as how fast the AI car should ideally be going when approaching a certain bend in the track. Because the speed is usually so fast, you are going to want your AI cars to be able to "read ahead" so they know what is coming in plenty of time to react (be that a simple deceleration, lane change or to avoid an obstacle). Also, assigning a Nav Agent just isn't going to make the car react in a realistic way. So at the very least you will probably need a system of race lines on your track (there are other ways but this is probably the simplest and gets good results), along with dedicated Car AI scripts and dedicated vehicle scripts assigned to each car as well.

    Its actually pretty challenging to get right and come up with a system that can handle all situations on various types of race track. I found the A.I portion of the project probably the trickiest to get right.
     
  7. Grieve_physics

    Grieve_physics

    Joined:
    Oct 25, 2012
    Posts:
    26
    Hi Gaski,

    Thanks for that, navmesh would have been great if it could have done it, Race Lines it is. Race Lines would be done with a simple waypoint system as a guess?

    Cheers again
     
  8. BobbyDoogle

    BobbyDoogle

    Joined:
    Dec 3, 2013
    Posts:
    17
    Hey this is perhaps a bit late to respond. But I had the same issue. In my project, the issue wasn't how fast the navagent actually turns, but just the rotation from a visual/aesthetics perspective. So, I thought I would share my neat solution, take direct control away form the navmesh agent, and set the transform using navmesh data:

    float speed = 10f; //however fast you want the rotation;

    void Start(){
    navAgent.updateRotation = false;
    }

    void Update () {
    Vector3 relativePos = new Vector3(navAgent.steeringTarget.x, transform.position.y, navAgent.steeringTarget.z) - transform.position;
    Quaternion rotation = Quaternion.LookRotation(relativePos);
    transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime*10);
    }
     
    Snouto likes this.