- Home /
UnitySteer - any way of determining when you've arrived at a node?
I'm aware of setting the OnArrive delegate- but that only tells you when you've arrived at your target. I'm using SteerToFollowPath, so I give it an array of nodes. Currently, OnArrive only fires when it reaches the end of the entire path. I need some sort of way to determine if I've arrived at an individual node (for AI behavior reasons).
Before I implemented UnitySteer, I was simply checking the SqrMagnitude difference between the next nodes' position and my AI's position.. if it was within the 'arrival' distance that I'd set up, it would fire an event.
However, now that UnitySteer is avoiding obstacles (beautifully I might add), it's obviously steering the AI off the path. The problem is that my previous logic no longer works, because as soon as the AI leaves the path, it never knows that we've skipped several nodes to bypass an obstacle, so my arrival events never fire.
UnitySteer is always aware of the next point in the path, and it's constantly steering for it- so it must have some sort of internal method of determining what node it's currently at, and which node it should be heading for.
My next step is to dive into UnitySteer and see if I can't reverse engineer the mechanics behind path traversal, but I figured I'd post here in case somebody had some insight that could save me a bit of digging.
Answer by testure · Jun 27, 2011 at 04:15 AM
Ah, another question with no replies. sad, sad...
Anyway, for those interested- There is no way to determine when you have arrived at a node when you're using SteerToFollowPath. I guess the nature of the vehicle behavior is that if it misses a node, it simply starts heading to whatever is the easiest to get to- so it doesn't actually have any concept of 'nodes'. It actually seems to keep track of segments, however.. and that you can actually determine that using one of Pathway's methods:
var tStruct = new PathRelativePosition ();
Debug.Log("We are on segment " + tStruct.segmentIndex);
From my testing though, it's pretty unreliable as a method for figuring out when you've hit a node. One would think that you could just detect when the segmentIndex changed, subtract one, and then there's your node index. That's not the case though- I'm not sure what's going on behind the scenes, but SteerToFollowPath actually changes segments a pretty good distance away from the node that would mark the start of that segment (as far as 8 meters away in some of my tests). I'm assuming that it has something to do with some internal prediction, but either way- it's not useful for my purposes.
I ended up just using SteerForPoint, and using the OnArrival delegate to increment the path on my own. It's not as fluid looking as SteerToFollowPath, but I suppose that's the trade-off.
Same here. I wrote my own class which uses arrival to advance points on a path. It's not really a bad solution and works quite well.
Your answer
Follow this Question
Related Questions
how and where can i download unity steer? 3 Answers
Unity steer for 2d game 1 Answer
Unitysteer 2.0 force output Vector 2 Answers
animation doesn't work??? 1 Answer
Integrating unitysteer with mixamo animation scripts 1 Answer