News › Forums › RAIN › General Discussion and Troubleshooting › Reset pathfinding by code
Tagged: pathfinding
This topic contains 4 replies, has 2 voices, and was last updated by Almuva 1 year, 4 months ago.
-
AuthorPosts
-
October 7, 2022 at 7:12 am #33392
Hello!
I’ve been searching in the forums but I’ve found nothing about this topic, and with only the API I don’t get the results I want…
The problem is: In the game, the player can step on floor where there’s no navmesh for the enemies, so when they are in ‘chasing’ state, sometimes they try to go where there’s no navmesh (this includes points in the air). I coded an algorithm that changes the destiny and finds a point on the navmesh, but now I need the pathfinder (or the navigator) to recalc the path to that point… and I don’t know how to do it well.
I thought that using AI.Navigator.RestartPathfindingSearch() was the solution, but in fact I don’t understand the API explanation:
” stops any running pathfinding searches for this AI and causes a new search to be started the next time a path is requested.”
How do I request a path?October 7, 2022 at 1:40 pm #33394Points in the air are not a problem. They map to the navmesh directly below them (unless they are very close to a navmesh above them). Points off the mesh entirely can’t currently be pathed to in the current version of RAIN. There is a new version of RAIN coming later this month that supports off-mesh pathfinding.
The Navigator will automatically recalculate a path when the move target changes, or after a call to RestartPathfindingSearch(). The path is typically only recomputed during movement, internally triggered by a Navigator.GetNextPathWaypoint call. There isn’t a way to force the navigator to recalculate its own internal path manually outside of that. Why would you need to trigger it manually?
October 8, 2022 at 2:24 am #33396Hey, thanks for the quick reply. The off-mesh pathfinding functionality sounds great!
Let’s see, I tried to simplify my problem as much as I could just to expose it here. This is what I got:
0: Scenario - Enemy sees player and chases him. Player can fall to the lower level but enemy can’t (he has to go to the left and use the stairs). If the enemy looses the player tries to go to the last point he saw him, that is, a point in the air where there’s no navmesh (at any ‘y’ for that position). So, my algorithm changes the destiny based on the direction of the player when the enemy looses him, and it is changed so it’s reachable.
1: As you say, the AI should recalc the pathfinding, but it doesn’t. The enemy remains at the point where he loosed sight of the player and doesn’t move (the cube pointed by the arrow is the reachable position, taken from aiRig.AI.Motor.MoveTarget.Position):
-> So, the enemy “gets stuck” there in the “move” state (chasePlayer). He has a destiny on the navmesh but doesn’t recalc the pathfind.
2: I debugged as much as I could and I can say that
A) Both the enemy and the destiny are on the same navmesh:
-> Let me say that the enemy actually can go to the lower level if he looses sight of the player on a reachable destiny. I mean, there has to be a path between those 2 points.
Debugging the navigator seems that it gets stuck because _pathfinding is true but _path is null (I’m not sure what does this mean, if it’s an error or not):
-> If I move the enemy in the scene view, he goes again to the image position.
This is all the info I got. I considered that the navigator tried to go to an imposible place (the mid-air pos with no navMesh under it) and got bugged, so when I changed the target it didn’t recalculate. That’s why I asked for a method to force the pathfinding recalc. But maybe the problem is other…
What do you think?
October 8, 2022 at 7:07 am #33401Still hard to tell what’s going on, but it certainly seems like there is no valid path from the AI to the player in (1). The AI is absolutely attempting to calculate a path, but is failing. Is it possible that the NavMesh has a gap or an island that makes the pathfind fail?
October 8, 2022 at 9:01 am #33404Well… This is awkward. It seems that part of my code caused the bug. There was a wrong if condition and the destiny was changed every update, and didn’t let RAIN recalc the path… or at least I think that was the problem, as I’ve changed some things at once. Now the condition is fine and the destiny changes once, and in the next update RAIN recalculates the path well.
Sorry! I’ll try not to do this again!
(At least your reply helped me to find that the problem was in my code. Thanks prime!)
-
AuthorPosts
You must be logged in to reply to this topic.