Search Unity

Using Unity's navigation system for cars on roads

Discussion in 'Navigation' started by DromoDesigner, Sep 13, 2018.

  1. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    73
    Hello,

    I am trying to recreate cars travelling down roads (similar to the roads in Cities:Skylines, but on a smaller scale).

    I am having trouble getting the cars to stick to their side of the road in two-way traffic. I have searched online for a solution or tutorial, but cannot find one.

    Would you please be able to recommend a tutorial or guide on how to get car to travel down roads, so that they stay on the correct side of the road even when turning?

    Thank you,
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    From what I know pathfinding on a navmesh might not really be a good idea for this.
    When it comes to cars driving around, you might be better off to define splines for each road that also contain a reference to their connected roads (turns and aheads on crossroads etc) and making your cars follow those instead.
    If you then make sure there's a spline on the road for each direction and provide some splines for making U-turns, you could get a pretty good basis.
     
    DromoDesigner likes this.
  3. thundercat71

    thundercat71

    Joined:
    Sep 13, 2018
    Posts:
    10
    When using nav meshes for simple roads and I do mean simple an invisible barrier down the middle of the road with a nav mesh obstacle applied will work. But this as I said is for simple layouts (grids).
     
    DromoDesigner likes this.