A* integration wander

nikbates

New member
I keep having issues with the wander task from the movement pack. It constantly tries to pick a wander destination that is outside of the grid.

How do I fix this
 

Justin

Administrator
Staff member
Can you insert some logging within Wander.TrySetTarget to see if the invalid destination is returning a valid state? Before Wander moves it attempts to sample the position to ensure it is valid.
 

nikbates

New member
I should have worded that better. It will pick a wander destination, but it doesn't factor in the outside of the graph. If its close to the edge of the walk able area it doesnt matter to its wander destination pick, meaning it will pick a wander spot outside of the graph causing the ai to just stand at the edge looking in the direction of the wander destination
 

Justin

Administrator
Staff member
The Wander task will randomly pick a destination until SamplePosition returns true. This is done randomly so it may take a few tries for it to return a valid destination, but as soon as SamplePosition returns true then it will move to that position. In this case it sounds like SamplePosition is returning true when you don't think that it should be. The SamplePosition uses AstarPath.active.GetNearest(position).node.Walkable to determine if that position can be traversed. Do you know of a better A* function to use?
 

nikbates

New member
The flee from the movement pack is also picking a flee destination that is not on the grid graph. It constantly chooses outside of the graph and tries to walk to get, gets to the edge of the graph and then endlessly circles
 

Justin

Administrator
Staff member
Do you know if there is a better way to sample the position in A* other than the GetNearest function?
 

Justin

Administrator
Staff member
I think that this is currently a limitation of the A* IAStarAI interface. I will reach out to the A* developer to see if he can add a method that is similar to the NavMesh version.
 

nikbates

New member
Okay if it is a limitation of the A* asset, why does it say the movement pack is integrated with the A* assets?
And why is there no indication of this on the store page?
 

Justin

Administrator
Staff member
The integration package covers most use cases but this is the first time that I have received this feedback. Give me a little bit of time to work with the A* developer to come up with a proper solution.
 

Justin

Administrator
Staff member
I may have a workaround for now - try downloading the A* integration again.
 

HappyRobot

New member
Still an issue:

https://gyazo.com/3925a4b5ae0fc09faa8189d1418ad927

It's not the first time though. I mentioned this a year ago here: http://www.opsive.com/forum/index.php?threads/movement-integration-a-bug.1870/post-9898

I have the latest version of behavior designer, movement pack, astar, and movement pack's astar integration. I'm still getting this same issue. At this point the wander task just isn't worth using as it'll lead to a the AI getting stuck after enough time.

Edit: Still stuck there this entire time I've been typing this. And I just noticed the destination is also above (And outside) the navmesh (mentioned this last year as well):

https://gyazo.com/d730e5b566bd5028caa396475f3a3465
 

HappyRobot

New member
Fixed this for myself, but it's a very specific case for my game. For anyone wondering: I edited SamplePosition in IAstarAIMovement.cs. I added a check for the proposed position to see if it's inside any given graph my AI is currently on.

https://gyazo.com/9cdab03d9b25668eaae6ba43c8989f16

Kinda ugly, but it works so I'm leaving it as is.

Edit: Also if you're only using 1 graph in your scene, this is much, much easier. Just do:

var direction = transform.InverseTransformDirection(AstarPath.active.GetNearest(position).position - position);
direction.y = 0;
bool isInside = Astar.active.data.<YourGraphType>.PointOnNavMesh(position, NMContraint.None) != null;
if (!isInside)
return false;
return direction.sqrMagnitude < arriveDistance.Value;

In my case I have multiple graphs so I need to do a little extra.
 
Last edited:

Justin

Administrator
Staff member
Thanks for posting your solution! I didn't know about PointOnNavmesh. I'll see if there is a generic way to retrieve that method.
 
Top