[Sorry for the appalling illustration!]
As i am still unsure what game this engine will turn into i am baking in plenty of functionality. The next ‘feature’ is AI vehicles which drive the streets (in a fairly dumb way) for themselves - i am not after making it 100% realistic, but they can do basic avoidance and navigate corners / junctions.
Obviously there is a distinct lack of help with game mechanics this specific so its a ‘from scratch’ approach and im sure there are much better ways than i have implemented it..
Each junction / branch or deviation in the road is given a waypoint which stores id, location, neighbouring waypoints, speed limit and ranking, the xml is currently:
<waypoint         id=”1”    x=”100”     y=”100”>
<neighbours>2,4</neighbours>
<speed>150</speed>
<rank>2</rank>
</waypoint>
The basic AI currently works by randomly travelling between waypoints. Each junction has a progression of events.
1. As the vehicle approaches a waypoint it slows to a reasonable cornering speed (usually much slower than the road speed limit)
2. When the vehicle reaches the waypoint border (each waypoint is defined by a circle with a diameter matching the road width) it checks to see if another vehicle is already using the junction - a simple ‘active = true’ is set within the waypoint object to signify this.
3. If the waypoint is clear the vehicle chooses the next waypoint from its list of neighbours (this will be affected by rank later, to account for side streets that are rarely used).
4. The steering and speed is adjusted to suit the new speed limit and direction! There are also some subtleties here, as cornering left and right involve travelling different radiuses/distances

[Sorry for the appalling illustration!]

As i am still unsure what game this engine will turn into i am baking in plenty of functionality. The next ‘feature’ is AI vehicles which drive the streets (in a fairly dumb way) for themselves - i am not after making it 100% realistic, but they can do basic avoidance and navigate corners / junctions.

Obviously there is a distinct lack of help with game mechanics this specific so its a ‘from scratch’ approach and im sure there are much better ways than i have implemented it..

Each junction / branch or deviation in the road is given a waypoint which stores id, location, neighbouring waypoints, speed limit and ranking, the xml is currently:

<waypoint         id=”1”    x=”100”     y=”100”>

<neighbours>2,4</neighbours>
<speed>150</speed>
<rank>2</rank>

</waypoint>

The basic AI currently works by randomly travelling between waypoints. Each junction has a progression of events.

1. As the vehicle approaches a waypoint it slows to a reasonable cornering speed (usually much slower than the road speed limit)

2. When the vehicle reaches the waypoint border (each waypoint is defined by a circle with a diameter matching the road width) it checks to see if another vehicle is already using the junction - a simple ‘active = true’ is set within the waypoint object to signify this.

3. If the waypoint is clear the vehicle chooses the next waypoint from its list of neighbours (this will be affected by rank later, to account for side streets that are rarely used).

4. The steering and speed is adjusted to suit the new speed limit and direction! There are also some subtleties here, as cornering left and right involve travelling different radiuses/distances