Traffic light for my node system

philip
2 min readDec 9, 2016

--

This blog will be about traffic lights.

So If you have read my previous blog I made a node system for npcs in a city just walking around randomly to different nodes. I blocked of nodes of different side of the street so npcs just wouldn’t walk across streets anywhere and for example get hit by cars.

So because of that I need to make traffic lights to make it possible for npcs to cross the street and do it in a way so they won’t get hit by cars.

So I just made a simple traffic light prefab added a script, made an enum with 3 for the different states green, red and yellow. Made timers for each state that you could change in the inspector.

So for connecting the nodes on one side of the street with the other node on the other side of the street I made a overlap box finding all colliders within that box then checking if it is a node then adding it to the list of available nodes.

So at this point they can cross at any point to get it working with the state of the traffic light I added another box for adding all the nodes that are connected to the traffic light so all the nodes that need to be closed when the traffic light turns red.

So because of this I need to change some of my code for selecting a new node to walk to, now I need to check if the next node is closed and if it is connected to a traffic light and if the node the npc is currently is on also is connected to the traffic light the npc needs to wait until the next node gets open again which will happen when the state of the traffic light turns green again.

--

--