Navmesh navigation is not working after enable control (cut scene)

Hi Guys,

Can anyone help me out the following issue, I used the same code in this lecture, but the Navmesh navigation is not working after playing the intro scene (after enabling the player control). Basically the issue is shown in below image that if I clicked the forward position (in red circle); expecting the player to move forward to that position however the player move backwards to other direction and the navigation just all incorrect. This only happens after this lecture, it works all normal before scene cut. Thank you in advance.

Do the enemies move? Do they move as they should? If the answer is yes then I can only think of one thing that could cause this sort of behavior: maybe the mouse position/raycast calculation got all wonky after re-enabling the player’s control for some reason.

Paste in your CinematicControlRemover script here and we’ll take a look to see what’s going on.

Thank you for your prompt reply, here is my CinematicControlRemover script, the enemy’s behavior is all correct. I did a bit testing, when I disabled the PlayerController script in Edit mode, then re-enable this script, this issue also occurs. Just wondering if any of you know any known situation could cause this issue, otherwise it could be my PlayerController script has some bugs which then I won’t borther you guys as that script is very to long, I’ll debug myself if it is problem of PlayerController script. Thank you all.

namespace RPG.Cinematics {

public class CinematicControlRemover : MonoBehaviour {

    GameObject player;

    private void Start() {      

       

        this.GetComponent<PlayableDirector>().played += DisableControl;

        this.GetComponent<PlayableDirector>().stopped += EnableControl;

        player = GameObject.FindWithTag("Player");

    }

    void DisableControl(PlayableDirector pd) {

        player.GetComponent<ActionScheduler>().CancelCurrentAction();

        player.GetComponent<PlayerController>().enabled = false;

    }

    void EnableControl(PlayableDirector pd) {

        player.GetComponent<PlayerController>().enabled = true;

    }

}

}

here is my ActionScheduler script.

namespace RPG.Core

{

public class ActionScheduler : MonoBehaviour

{

    IAction currentAction;

    public void StartAction(IAction newAction)
    {
        if (currentAction == newAction) return;

        if (currentAction != null)

        { 
            currentAction.CancelCurrentAction();
        }

        currentAction = newAction;
    }

    public void CancelCurrentAction()
    { 
        StartAction(null);

    }

}

}

Thank you for your prompt reply, the enemy is all correct behavior, please see my response below. Thanks.
Follow up:
I’ve done some test, that even if I use a basic capsule obj and basic movement script like below script, once I manually disable this script and re-enable the script in play mode, the Navmesh naigation is not working properly again. This is odd, I created new terrain, new capsule obj, new movement script to just testing, but still have the same issue, is it because Unity’s own issue? my Unity version is 2020.3.9f1.

Hi Bran,
I’ve done some test, that even if I use a basic capsule obj and basic movement script like below script, once I manually disable this script and re-enable the script in play mode, the Navmesh naigation is not working properly again. This is odd, I created new terrain, new capsule obj, new movement script to just testing, but still have the same issue, is it because Unity’s own issue? my Unity version is 2020.3.9f1.

using System;

using UnityEngine;

using UnityEngine.AI;

public class tempController : MonoBehaviour

{

// Update is called once per frame

void Update()

{

    if (Input.GetMouseButton(0))

    {

        MoveToCursor();

    }

}

private void MoveToCursor()

{

    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);;

    RaycastHit hitObj;  

    bool hasHit = Physics.Raycast(ray, out hitObj);

   

    if (hasHit)

    {

        GetComponent<NavMeshAgent>().destination = hitObj.point;

    }

}

}

I’m going to need a closer look at the project.
Zip up your project and upload it to https://gdev.tv/projectupload
Be sure to remove the Library folder to conserve space (I have to regenerate it anyways)

Hi Brain,

Thank you for your kindness, fortunately I just found the reason, it’s due to my incorrect use of CinemachineVirtualCamera, after recreating the virtual follow camera, then it just all worked. Though don’t know which parameter was not correct before, but now it’s all good. Thank you a lot for your prompt response and help.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms