Search Unity

Car navigation agent

Discussion in 'Navigation' started by 230000751, Aug 5, 2015.

  1. 230000751

    230000751

    Joined:
    Jul 30, 2015
    Posts:
    12
    Hi. I was working with navigation meshes and agents and everything seemed to work just fine until I came across a problem when making a car use a navigation mesh and nav agent. It seems to head straight for the target regardless of what direction it is facing. The object does turn according to it's angular velocity but that has no effect on the way it moves. I keep getting the action on the left instead of what I want the car to do which is on the right. It looks really weird in the game. A car cannot travel sideways as it is constantly doing.
    im3.png

    Does anyone know what to do here?
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    You will have to manage the car movement yourself rather then letting the agent do it.
     
  3. 230000751

    230000751

    Joined:
    Jul 30, 2015
    Posts:
    12
    Oh. That is what I was afraid of. So I guess I need to use the rotateTowards function and RigidBody.addVelocity to move the car more realistically. And for obstacle detection, raycast?
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,435
  5. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    I used wheel colliders for my vehicles, so I dont need to worry about adding force or torque. Its just a case of figuring out the correct steering angles (not too hard), and if you are wanting the car to go forward/back.

    Obstacle avoidance is generally raycast, but it depends on your terrain.