# City traffic Lanes

 0 Here's a suggestion... This won't solve the problem, but it might help to get outside the box...Use one set of waypoints, running down the middle of the street.But instead of having your cars try to line up the center of the car with the waypoint path, have the car line up with a point set just outside the driver's side door.That way, cars can use either set, and the side of the road they are on will be defined by the way they are going.Would only work for two lane roads, but I could see the use of a Lane variable that would move the car farther and farther away from the middle... more ▼ answered May 31 '12 at 08:53 PM Tasarran 1.1k ● 12 ● 21 ● 27 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Car AI is quite a challenging thing to do (as is any form of AI actually). The easiest solution that I can think of, is to just check which side of the road your car is on and adjust the steering behaviour accordingly. For checking, you can do something like ``````Vector3 v_direction = v_currentWaypoint - v_lastWaypoint; // assume waypoints are Vector3s and set in the middle of the road Vector3 v_right = Vector3.Cross(v_direction, Vector3.up); if(Vector3.Dot(transform.position - v_lastWaypoint, v_right) > 0) // you're on the right side else // you're on the left side ``````Alternatively, you could define your navmesh(es) by using one-way waypoints only. So you basically have a set of waypoints for each lane and only allow traversing them in one direction (this can usually be achieved by just not setting the previous waypoint as a neighbour of the following one.For decisions on crossroads: I would just randomly select any waypoint on the navmesh and let the pathfinding do the rest. If the car reaches the waypoint, just pick another one. Or you could just scrap pathfinding altogether for that and random pick one of the neighbouring waypoints.Quick Edit: This will only take care of your very basic navigation needs. You will still have to deal with stuff like avoiding obstacles, trafic signals and so on more ▼ answered May 28 '12 at 01:26 AM hathol 1.6k ● 4 ● 11 Voting for informity. I can do traffic lights and obsatcle avoiding pretty easily. The changing the steering for each side of the road doesn't sound such a good idea, as each car would keep seem to try to steer into the middle of the road before correcting itself, so that wouldn't look great. The alternative idea could be good. It's not really the sides of roads that's a problem, I guess. because by choosing random paths at junctions, the traffic will already look like it's driving in multiple lanes due to the choices they make. So there's an update to the question. May 28 '12 at 09:13 PM Fishman92 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x423
x296
x170
x12
x2

asked: May 27 '12 at 08:59 PM

Seen: 1037 times

Last Updated: May 31 '12 at 09:17 PM