News › Forums › RAIN › General Discussion and Troubleshooting › AI goes off graph when navmesh has a gap
Tagged: Navigation Navmesh Gaps
This topic contains 9 replies, has 3 voices, and was last updated by Xkynar 3 weeks, 1 day ago.
-
AuthorPosts
-
June 30, 2022 at 6:07 pm #40469
I really tried to avoid asking for help but I really can’t understand this behaviour. I have a navmesh with gaps, and I made a custom script which fills a moveTarget variable with the place where my mouse clicks, so that i can move there. When i click a point in the navmesh which should not be possible to go, the AI just leaves the graph and goes straight to the point, sometimes even through the air.
Here are some screenshots to contextualize:
Here is the script of mouseclick:
using UnityEngine; using System; using System.Collections; using System.Collections.Generic; using RAIN.Action; using RAIN.Core; using RAIN.Representation; using RAIN.Navigation; [RAINAction("Wait For Click")] public class WaitForClick : RAINAction { public Expression MoveTargetVariable = new Expression(); public override ActionResult Execute(RAIN.Core.AI ai) { if (Input.GetMouseButton(0)) //on mouse click { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100)) //if click hits something { if (NavigationManager.Instance.GraphForPoint(hit.point, ai.Motor.MaxHeightOffset, NavigationManager.GraphType.Navmesh, ((BasicNavigator)ai.Navigator).GraphTags).Count != 0) //if the point is on a navmesh { RAIN.Navigation.Pathfinding.RAINPath path; if (ai.Navigator.GetPathTo(hit.point, int.MaxValue, float.MaxValue, false, out path)) //if there's an actual valid path to the point { ai.WorkingMemory.SetItem<Vector3>(MoveTargetVariable.VariableName, hit.point); return ActionResult.SUCCESS; } } } } return ActionResult.FAILURE; } }
As you can see, even when I actually check if there’s a valid path, it still returns true even though there’s a gap, and then the AI proceeds to go to the point even if it needs to fly. Why does this happen? How can I handle this situation? Thank you very much.
- This topic was modified 1 month, 1 week ago by Xkynar.
July 1, 2022 at 6:55 am #40472Have you tried to add NavMeshAgent to your character?
July 1, 2022 at 7:00 am #40473Isn’t NavMeshAgent a Unity component, not RAIN’s?
July 1, 2022 at 7:05 am #40474It is. But you can still use it for navigation. Using NavMesh from Unity gives more accurate results. Not sure if this will help you overcome your issue.
July 1, 2022 at 7:23 am #40475But doesn’t that mean that I can’t use RAIN?
July 1, 2022 at 7:36 am #40476You still can use both systems at the same time. Rain only provide a different interface for using navmesh in unity.
July 1, 2022 at 8:25 am #40477I see. The problem is, Unity’s navmeshes are scene-stored, and my goal is to create a procedurally generated map, so I don’t think Unity is better than RAIN at achieving this, at least for now… Anyhow, I’d still like to understand how to solve this problem with RAIN alone.
July 1, 2022 at 1:45 pm #40480I also had this problem, but I just adjusted my scene a little to prevent gaps in my navmesh, since I wanted everything connected. The problem that I found was that the selected point was still a valid point on the NavMesh as far as RAIN was concerned. And since the move behavior is close sourced, I couldn’t figure anything out beyond there.
Honestly, sounds like GetPathTo is bugged, or passing in int.MaxValue, float.MaxValue for number of steps / path length is causing problems. Have you tried using smaller values to see if that does anything?
July 1, 2022 at 1:58 pm #40481Ye it doesn’t change anything. And ye, the fact that it is close sourced (comprehensively) makes it hard to figure it out. I wish Sigil or Prime could give their insights…
July 17, 2022 at 6:32 pm #40504bump
-
AuthorPosts
You must be logged in to reply to this topic.