Friday, June 02, 2006

Hyperplanes, Normals & Vectors

Lot's of work over this week including a major overhaul of the waypoints system which was far from ideal. Previously the vehicles aimed for specific points on the track, a distance check was then used to decide whether the car had reached the waypoint - this resulted in a circular detection area.


The major drawbacks of this approach are that if you drive off the track you can completly miss a waypoint without realising and the lap wont be counted, ai cars all aim for the same point which results in them driving in a line on the same route and the start finish line is actually a circle! The solution has been to replace points with lines, the ai can then pick different points on the line to aim for resulting in a more unpredictable race. It is also possible to find if a waypoint has been passed by calculating the normal of the line and projecting the distance from the car to the line onto that - if the number is below zero then the line has been passed. For this Metanet has been a great help as always! The other great thing about this method is that the line never has to be phyisically touched as it is calculated as if the line continutes into infinity in both directions...


I have also integrated waypoint editing / saving / loading into the track editor. The ends of lines can be dragged to move the waypoint and the red arrow signifies direction. (The track is displayed half size in the editor)


I think once the AI cars are more aware of the other vehicles around them this will provide a really good level of challange, at the moment they like to cross each others paths too often, which results in cars scraping along next to each other...

No comments: