News Forums RAIN General Discussion and Troubleshooting Navigation Mesh: Walking Radius problem

This topic contains 35 replies, has 4 voices, and was last updated by  prime 3 months, 2 weeks ago.

Viewing 15 posts - 1 through 15 (of 36 total)
  • Author
    Posts
  • #32650

    book
    Participant

    I have a problem when the AI enemy follows the player. When the player is standing near a wall (that is part of the walkable radius) the enemy can’t reach the player (walkable radius is 5.5). When I make the walkable radius of the navigation mesh smaller the enemy just keeps bumping into walls.

    How do I make the enemy seek the player even if the player is standing next to a wall.

    #32661

    book
    Participant

    Hello again.

    I’m also having a similar problem with my throwing mechanic. In my game when I throw an item, the enemy will hear where it lands and run to that position to inspect the item ( the position of where the item landed).

    The only problem is when the thrown item lands in the “walkable radius” area of the navigation mesh (i.e: not on the navigation mesh) beside a wall the enemy behaves randomly and usually just moves in circles.

    How do I check if an object is not reachable and is not on the navigation mesh anymore.

    I really need someones help with this.

    Thank you guys.

    #32989

    book
    Participant

    Hi can anyone help me with my previous problems. I’m still unsure how to do it.

    I would really appreciate it. It’s one of the final things I have to fix with my AI alien.

    I’m making a horror game, with some stealth elements. ie: throwing items to distract the alien monster.

    #32994

    prime
    Keymaster

    It’s a bit of a tough problem, but there are some reasonable solutions.

    In Zombie Playground we solved this by using two Navmeshes. The first was the normal “I like to walk here” mesh. The second was a fallback mesh that the AI would use if it couldn’t find a path with the preferred mesh. We changed the Motor to automatically switch meshes when the first mesh fails.

    A second option would be to use something like the attack harness, which defines positions around the target that are on the walkable mesh. The AI can query for these to find a valid walk point, then move there.

    When I get back to my office I’ll see if I can grab some code to share.

    #33029

    book
    Participant

    Thanks Prime. Yeah that would be great if you can find some code. I’ve been stuck on this for ages. :-p

    #33045

    prime
    Keymaster

    Haven’t had a chance to get to it just yet, but I haven’t forgotten. Please bump this thread if you don’t see something within a couple more days.

    #33089

    book
    Participant

    Hi Prime. Post BUMPED as requested. Thanks!

    #33130

    prime
    Keymaster

    Here’s an example of a custom motor that switches between two navmeshes. Here are the important parts:

    - Create 2 navmeshes. One called WalkableMesh which should be your standard mesh when things are working normally. The other should be called FailureMesh. FailureMesh should have the walkable radius set extremely small or zero, so that objects that would otherwise be outside the walkable area can still be navigated to.
    - Add the graph tag “standard” to the WalkableMesh.
    - Add the graph tag “failure” to the FailureMesh.
    - Set the DualNavmeshMotor as your AI Motor in RAIN.

    Here’s what will happen. RAIN will always check to see if both the AI and the target points are on the walkable mesh. If they aren’t then RAIN will switch to using the failure mesh. Path recalculation is automatically done by the Navigator, so you don’t have to do anything special when you switch meshes.

    Problems:
    - In the failure case, the AI will hug walls and corners as it moves
    - There is no guarantee that a valid path can be found. We’re still working on a different solution for that.

    * Disclaimer - I haven’t tested this code in a while, and it is possible that it has a bug or two. Give me a shout if you run into trouble.

    using System;
    using System.Collections.Generic;
    using UnityEngine;
    using RAIN.Core;
    using RAIN.Motion;
    using RAIN.Navigation;
    using RAIN.Navigation.NavMesh;
    using RAIN.Navigation.Graph;
    using RAIN.Serialization;
    [RAINSerializableClass]
    public class DualNavmeshMotor : BasicMotor
    {
    	private List<string> failureTagList = new List<string>();
    	private List<string> standardTagList = new List<string>();
    	private NavMeshPathGraph walkableMesh = null;
    	private NavMeshPathGraph failureMesh = null;
    	public override void AIInit ()
    	{
    		base.AIInit ();	
    		failureTagList.Clear();
    		standardTagList.Clear();
    		failureTagList.Add("failure");
    		standardTagList.Add("standard");
    	}
    	public override bool Move ()
    	{
    		BasicNavigator nav = AI.Navigator as BasicNavigator;
    		if (walkableMesh == null)
    			walkableMesh = NavigationManager.Instance.GetNavigationGraph("WalkableMesh") as NavMeshPathGraph;
    		if (failureMesh == null)
    			failureMesh = NavigationManager.Instance.GetNavigationGraph("FailureMesh") as NavMeshPathGraph;
    		if (nav.GraphTags.Count == 0)
    			nav.AddGraphTag("standard");		
    		if (nav.CurrentGraph == walkableMesh)
    		{
    			if (!walkableMesh.IsPointOnGraph(AI.Kinematic.Position, AI.Motor.StepUpHeight) || (!walkableMesh.IsPointOnGraph(AI.Motor.MoveTarget.Position, AI.Motor.StepUpHeight)))
    			{
    				nav.AddGraphTag("failure");
    				nav.RemoveGraphTag("standard");
    			}
    		}
    		else if (nav.CurrentGraph == failureMesh)
    		{
    			if (walkableMesh.IsPointOnGraph(AI.Kinematic.Position, AI.Motor.StepUpHeight) && (walkableMesh.IsPointOnGraph(AI.Motor.MoveTarget.Position, AI.Motor.StepUpHeight)))
    			{
    				nav.AddGraphTag("standard");
    				nav.RemoveGraphTag("failure");
    			}
    		}
    		return base.Move ();
    	}
    }
    • This reply was modified 5 months, 3 weeks ago by  prime.
    • This reply was modified 5 months, 3 weeks ago by  prime. Reason: fixed code bugs
    #33190

    book
    Participant

    Thank you for this! But still having some difficulty getting it working properly.

    Ok I think I have got everything set up the way you said. No more errors.
    - Two navigation meshes created. One small radius, one larger radius.
    - Graph names and graph tags are set up on the two navigation meshes.
    - The DualNavmeshMotor is set up as the AI motor.

    In the code I had to change AI.Motor.MoveTarget.Position to AI.Motor.moveTarget.Position to get that working.

    ******************************

    But the problem is he is bumping into things more than ever now. He rarely bumped into something with just the one mesh (That one mesh was at 0.7 walkable radius.)

    Of the two nav meshes now in the scene the AI alien seems to be using the nav mesh with the smallest walkable area, even when he doesn’t need to. He is bumping into walls the whole time if one of the two meshes has a low walkable radius.

    - If I set either one of the two nav meshes to a low value the AI alien bumps into walls.
    - If both of the nav meshes have a higher value (around 0.7) it is fine.

    …Confused

    #33193

    prime
    Keymaster

    1) What version of RAIN? (The latest doesn’t have AI.Motor.moveTarget)
    2) Doesn’t sound like everything is set up just right. Did you add the graph tags to the nav meshes correctly? Are they named correctly?

    #33205

    book
    Participant

    I had been using the RAIN version 2.0.11.0
    So last night I updated RAIN to version 2.1.3.0

    I changed the code back to AI.Motor.MoveTarget.Position after updating



    ********************************************************************************************

    After updating the project I am getting these errors when the AI alien is walking around:

    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    System.Collections.Generic.List
    1[RAIN.Navigation.Graph.NavigationGraphNode].get_Item (Int32 index) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
    RAIN.Navigation.Graph.RAINNavigationGraph.GetNode (Int32 index)
    RAIN.Navigation.NavMesh.NavMeshPathGraph.Localize (Int32 nodeIndex)
    RAIN.Navigation.Pathfinding.AStarPathFinder.GetNode (RAIN.Navigation.Graph.RAINNavigationGraph graph, Int32 graphIndex)
    RAIN.Navigation.Pathfinding.AStarPathFinder.FindPath (RAIN.Navigation.Graph.RAINNavigationGraph graph, Int32 fromGraphIndex, Int32 toGraphIndex, Int32 maxIterations, System.Collections.Generic.List<code>1& indices, System.Collections.Generic.List</code>1& positions, System.Single& cost)
    RAIN.Navigation.BasicNavigator.GetPathToMoveTarget (RAIN.Navigation.Pathfinding.AStarPathFinder finder, RAIN.Motion.MoveLookTarget target, Int32 maxIterations, RAIN.Navigation.Pathfinding.RAINPath& path)
    RAIN.Navigation.BasicNavigator.GetPathToMoveTarget (RAIN.Navigation.Pathfinding.RAINPath& path)
    RAIN.Navigation.BasicNavigator.GetNextPathWaypoint (Boolean allow3DMovement, RAIN.Motion.MoveLookTarget cachedMoveLookTarget)
    RAIN.Motion.BasicMotor.Move ()
    DualNavmeshMotor.Move () (at Assets/AI/Actions/DualNavmeshMotor.cs:59)
    RAIN.BehaviorTrees.Actions.MoveAction.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTActionNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTWaypointNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTParallelNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTConstraintNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTSelectorNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTConstraintNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTSelectorNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTParallelNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.Minds.BasicMind.Think ()
    RAIN.Core.AI.Think ()
    RAIN.Core.AIRig.AIUpdate ()
    RAIN.Core.AIRig.Update ()

    ***************************************************************************************
    These errors I get less frequently but still come up.

    NullReferenceException: Object reference not set to an instance of an object
    DualNavmeshMotor.Move () (at Assets/AI/Actions/DualNavmeshMotor.cs:43)
    RAIN.BehaviorTrees.Actions.MoveAction.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTActionNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTWaypointNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTParallelNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTConstraintNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTSelectorNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTConstraintNode.Execute (RAIN.Core.AI ai)
    RAIN.BehaviorTrees.BTNode.Run (RAIN.Core.AI ai)

    ******************************************************************

    Argument is out of range.
    Parameter name: index
      at System.Collections.Generic.List
    1[RAIN.Navigation.Graph.NavigationGraphNode].get_Item (Int32 index) [0x0000c] in /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633 
      at RAIN.Navigation.Graph.RAINNavigationGraph.GetNode (Int32 index) [0x00000] in <filename unknown>:0 
      at RAINEditor.Navigation.NavMesh.NavMeshEditor.DrawNavMeshForScene (RAIN.Serialization.FieldWalker aWalker) [0x00000] in <filename unknown>:0 
      at RAINEditor.Navigation.NavMesh.NavMeshEditor.DrawScene (RAIN.Serialization.FieldWalker aWalker) [0x00000] in <filename unknown>:0 
      at RAINEditor.TypeEditors.RAINTypeEditor.DrawFieldForScene (RAINEditor.Core.RAINComponentEditor aComponentEditor, RAIN.Serialization.FieldWalker aWalker) [0x00000] in <filename unknown>:0 
      at RAINEditor.Navigation.NavMesh.NavMeshRigEditor.DrawComponentForScene (RAIN.Serialization.FieldWalker aWalker) [0x00000] in <filename unknown>:0 
      at RAINEditor.Core.RAINComponentEditor.OnSceneGUI () [0x00000] in <filename unknown>:0 
    UnityEngine.Debug:LogError(Object)
    RAINEditor.Core.RAINComponentEditor:OnSceneGUI()
    UnityEditor.DockArea:OnGUI()
    • This reply was modified 5 months, 2 weeks ago by  book. Reason: Clean up code
    #33206

    book
    Participant

    Here are images of my settings:

    WalkableMesh

    FailureMesh

    AI

    #33208

    prime
    Keymaster

    Can you send that project to us for testing? It would be extremely helpful in tracking down that exception, and then we can turn around a solution asap.

    Coordinate with jester at rival theory dot com to send the file over.

    Thanks!

    #33236

    book
    Participant

    Just to update, I sent that project on to Jester yesterday.

    #33238

    prime
    Keymaster

    Problem has been found and fixed. We’ll post an update in the next few days.

    We’re also working on a solution that will remove the need for dual navmeshes and support pathfinding to off-mesh objects.

Viewing 15 posts - 1 through 15 (of 36 total)

You must be logged in to reply to this topic.