Hi,
I’ve implemented Navmesh generation from sidewalks. Then I linked some of the trangles with UserConnections, which stand for a crosswalk each. My question is now, how would you implement a traffic light? My idea is to set an additional flag on the Node, which is similar to “walkable”, but which is not interpreted by the pathfinding. Let’s call this flag “redLight”. The seeker checks for that flag on each node it switches to (current node) and once it found that flag, it stops the whole seeking and walking until the light turns green.
Do you think this is a reasonable approach? And how (or better: where) would you implement that behaviour? Extend the seeker, add a new path modifier or create a separate behaviour component that controls the seeker?
You could use tags. http://arongranberg.com/astar/docs/tags.php
Your movement script could follow the path, and when it detects that it is about to walk on a crosswalk, it will first check that it the light is not red before it walks, otherwise it will wait. Do not extend the seeker, instead write a movement script which calls the seeker. Using this approach you could also add a small penalty to traversing crosswalks.
I don’t yet get the tags thing, but controlling the Seeker and AIPath from a third component looks like a fine idea.
At the moment I’m extending Node, UserConnection and AstarPath.ApplyLinks. UserConnection got an additional flag which is applied to the nodes in ApplyLinks. Now the plan is to ask the seeker for the current and next nodes. Problem is that if a special node is within the “Pick next waypoint dist” range or it was passed since the last fixedUpdate, it’s simply skipped by AIPath.CalculateVelocity.
So how would you check whether the seeker currently stands on a special tagged node/triangle?
The super easy way would be: Node node = AstarPath.active.GetNearest (transform.position).node; if (node.tag == 1) { //Or some other tag Debug.Log ("We are standing on a marked node"); }
Thanks, but I guess I asked my question a little bit wrong.
What I have is an attribute in Node, that tells which node it has a special crosswalk connection to. I’ve implemented that as a dictionary, where all keys are connected nodes and the values tell if that connection should cause a seeker stop or not.
It’s easy to get the node the seeker is standing on with your code, but while the seeker stands on that node, the path (Seeker.GetCurrentPath) might not contain the other part of the connection anymore, depending on the settings.
What I’m gonna try now is iterating over the whole path every time it’s recalculated and saving all crosswalks (by their index in the path) in a separate attribute. Then, in Update, I can check whether the rest of the path has a length where it should have passed a crosswalk. E.g. if there was a crosswalk detected on nodes 4 and 5 in a 20 nodes path, then you can tell that you are on a crosswalk if the current path length is 16 or less.