News Forums RAIN General Discussion and Troubleshooting AI goes off graph when navmesh has a gap

This topic contains 9 replies, has 3 voices, and was last updated by  Xkynar 3 weeks, 1 day ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #40469

    Xkynar
    Participant

    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.
    #40472

    Ibrahim
    Participant

    Have you tried to add NavMeshAgent to your character?

    #40473

    Xkynar
    Participant

    Isn’t NavMeshAgent a Unity component, not RAIN’s?

    #40474

    Ibrahim
    Participant

    It 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.

    #40475

    Xkynar
    Participant

    But doesn’t that mean that I can’t use RAIN?

    #40476

    Ibrahim
    Participant

    You still can use both systems at the same time. Rain only provide a different interface for using navmesh in unity.

    #40477

    Xkynar
    Participant

    I 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.

    #40480

    delphinius81
    Participant

    I 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?

    #40481

    Xkynar
    Participant

    Ye 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…

    #40504

    Xkynar
    Participant

    bump

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.