Forum rules - please read before posting.

NavMeshAgentIntegration and Hotspot Interaction Issues

edited December 2021 in Technical Q&A

Hey!

I'm having some problems trying to use the NavMeshAgentIntegration script for my player character. When the player is using NavMeshAgent movement and I interact with a Hotspot, it navigates to the hotspot but never triggers the action.

My player movement is set up as following: AC's motion control is set to manual, and the NavMeshAgentIntegration's Use AC for speed/turning properties are disabled. The NavMeshAgent's speed is controlled by root motion in OnAnimatorMove using the animator delta position, and the NavMeshAgent's turning is controlled by the navmeshagent script.

Using this setup navigation works perfectly, i can move to any point and it will reach it perfectly.The issue is that it seems like AC never detects that the character has "reached" the Hotspot, so it never starts the Action assigned. If i trigger the action manually using Interact() it works perfectly. If i give the motion control back to AC, then the hotspot interaction works perfectly. Also if i enable Use AC for turning in the NavMeshAgentIntegration script, the interaction works again. The problem occurs only when speed and turning are being controlled by the NavMeshAgent.

Here's two videos of this issue. In the first one, I'm running my custom movement setup with the NavMeshIntegration script. When I click the hotspot to interact, the player moves up to the hotspot, then stops and doesn't do anything else. Afterwards i launch the action trough a ingame debug console that just calls Interact() from the action.

And in the second video I've changed AC's motion control to automatic, disabled all the NavMeshAgent related components and the hotspot works as intended.

Could anyone point me in the direction of where this problem might come from? I suspect its a variable somewhere which is not being correctly updated through the NavMeshAgentIntegration script. Thanks! :smile:

Edit: I'm running AC Version 1.72.3 if that helps.

Comments

  • Can you share the Inspector of your Player, the Hotspot, and the custom script you're using? I can only make general suggestions otherwise.

    The NavMeshAgentIntegration script sets the character's Motion control field automatically. If Use AC For Turning is checked, then it will set this to Just Turning, which causes the Char script's DoTurn function to be run, but not MoveUpdate.

    If your Hotspot's Interaction panel has Face after? checked, then the game will first wait for the Player to reach the Hotspot, and then wait for them to face it. If this is checked, test unchecking this to see which step is being waited for indefinitely.

    This wait occurs in the PlayerInteraction script's UseObject coroutine. If you want to check this, look for the checks of "button.playerAction" - two separate sets of wait code are run, depending on the Hotspot's Player action setting.

  • Sure! Here's the Inspector for the Player, the Hotspot and the Agent. The custom script is just doing this:

    private void OnAnimatorMove()
    {
        if (!agent || !animator)
        {
            return;
        }
    
        if (animator.deltaPosition == Vector3.zero || Time.deltaTime == 0)
        {
            return;
        }
    
        agent.speed = (animator.deltaPosition / Time.deltaTime).magnitude * SpeedMultiplier;
    }
    

    Indeed the hotspot has Face after? activated. Disabling it fixes the issue, so it must be this step that is being waited for indefinitely. I'm going to check the PlayerInteraction script to see if i can fix this. Thank you Chris! :)

  • edited December 2021

    I think i figured out what was going on and how to solve it. For some reason, once the character arrived to the hotspot, IsTurning() would remain true forever, so the check inside the coroutine from PlayerInteraction would never exit the loop. I tried modifying the look direction at different points when navigating and that sometimes kinda' worked, but caused additional issues, and it felt also a bit too complex.

    So the solution is way simpler, as always. Giving control back to AC when the character is decelerating or idle makes sure that all the AC related features like facing the hotspot work, and having the navmeshagent taking control when the player is moving gives me nice pathfinding and avoidance. Yay!

    I just modified the set motion control function for this, hopefully there's no more problems down the line.

    private void SetMotionControl ()
    {
        if (useACForTurning)
            {
            _char.motionControl = MotionControl.JustTurning;
        }
        else
        {
            //IF CHARACTER'S IDLE OR DECELERATING AND THE MOTION CONTROL IS SET TO MANUAL, CHANGE IT TO JUST TURNING FOR THE HOTSPOTS TO WORK CORRECTLY
            if (_char.charState != CharState.Move && _char.motionControl == MotionControl.Manual)
            {
                _char.motionControl = MotionControl.JustTurning;
            }
            else
            {
                //IF THE CHARACTE IS MOVING, GIVE CONTROL BACK TO NAVMESHAGENT
                if (_char.charState == CharState.Move && _char.motionControl == MotionControl.JustTurning)
                {
                    _char.motionControl = MotionControl.Manual;
                }
            }
        }
    }
    

    Thanks again :)

  • No problem.

    About these changes you're making: the NavMeshAgentIntegration script is designed to be standalone. If you want to make changes to it, you can duplicate/rename it and use this copy without it interfering with other AC scripts.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.