First AI approach for the traffic system

First AI approach for the traffic system

Unity3D Video Game Development MiniTrue

With more than one vehicle on the road a little bit of artificial intelligence is needed.

I decided to attach three Unity3D collider (with activated “trigger” property and one rigidbody component) to each vehicle:

  • An active front collider to detect if the vehicle is about to crash into another car or pedestrian
  • A passive body collider to be detected by the front collider of another vehicle
  • A passive back collider – also to be detected by another front collider

First idea of the collider and the AI behavior:

AI

If the front collider of the vehicle hits a body collider it stops and tries to drive back a little bit.

When the back collider is hit, the other car is probably just driving on the same track but with less speed. In this case the vehicle with the triggered front collider adjusts to the speed of the car in front of it.

The result looks more like a cartoon character using trial and error than a defensive driving style. I call this AI behavior “Italian driving mode” ;-)

AI

AI

BTW: One thing I learned about Unity3Dwhile working on this: Because Unity seems to serialize enums as numbers and not by name: Use a flag number for every enum value. Otherwise when you change the order inside the enum definition the meaning swaps.

Categories: Unity3D , Video Game Development , MiniTrue

Tags: Unity3d , Enums , Collider , Trigger , Rigidbody , Programming , Artificial Intelligence , Videogame

QR-Code dieses Beitrags


Dieser Blog-Artikel beinhaltet keine bezahlten Produktplatzierungen.
Bei Affiliate-Links oder Rabatt-Codes entstehen für den Leser keine Kosten oder Nachteile. Bei einem Kauf über diesen Link/mit diesem Code erhält der Betreiber eine prozentuale Provision und/oder gewährt dem Käufer einen Rabatt in angegebener Höhe.