You should use the "GamePlay.gpFindPath()" method to let the game engine calculate the waypoints. This way the car will not cross water and use roads and bridges.
As the calculation of the waypoints is done asynchronous (in a different thread) you have to wait until the calculation is finished:
Code:
IRecalcPathParams pathParams = GamePlay.gpFindPath(start, 10.0, end, 20.0, PathType.GROUND, groundGroup.Army);
// start is the start coordinate, end it the end coordinate, 10.0 and 20.0 how much the calculated way is allowed to differ from start and end point.
while (pathParams.State == RecalcPathState.WAIT)
{
Game.gpLogServer(new Player[] { Game.gpPlayer() }, "Wait for path.", null);
// This is not a good idea, I think this would stop the game thread. Better check if the path calculation is finished within the OnTick() method.
System.Threading.Thread.Sleep(100);
}
if (pathParams.State == RecalcPathState.SUCCESS)
{
Game.gpLogServer(new Player[] { Game.gpPlayer() }, "Path found (" + pathParams.Path.Length.ToString() + ").", null);
groundGroup.setWay(pathParams.Path)
}
else if(pathParams.State == RecalcPathState.FAILED)
{
Game.gpLogServer(new Player[] { Game.gpPlayer() }, "Path not found.", null);
}
Note that his should only show you the usage. It's not a good idea to sleep the thread while the game is running. I do it for the IL2DCE mission generation when I create the mission - but at this stage the mission is not running.
Look for navyr's tank war example how to check the result of the path calculation within the OnTick() method.