Forum rules - please read before posting.

Pathfinding for player using First Person Movement method

Hi,

I'm trying to move my Player prefab using pathfinding, but also have the Movement method set to First Person where the cursor is locked to the center of the screen and the mouse can rotate the camera to look around (like the setup in the AC First Person game tutorial: ).

Pathfinding for the player doesn't seem to work while the movement method is set to First Person, only Point and Click seems to work. However, with Point and Click the camera doesn't rotate like in First Person. I tried using a custom camera script to get rotation while in Point and Click movement, but am running into issues with pathfinding working going that route. Ideally getting pathfinding to work in First Person movement would be my preference. Does anyone have any suggestions on how to do this?

Thanks

Comments

  • I'm not clear - are you looking to rely on point-and-click movement in First Person, or just use Character: Move to point Actions to move the Player?

    The latter should work with First Person movement provided that the NavMesh is set up, and that the Action has Wait until finish? checked.

    You may be interested in the "Movement template: Nodes" package on the Downloads page, as allows for point-to-point first person movement.

  • edited January 13

    Sorry I wasn't clear. I'm actually trying to set it up so the player can click on the ground and move to that point they clicked on, but still be able to look around like the movement method is in First Person. I made a short video to show what I mean:
    The first part of the video the movement method is in First Person and I'm able to look around using the cursor locked to the center of the screen. The last part of the video I changed the settings to Point and Click movement so the pathfinding using a navmesh would work (sorry if the last part is hard to see, but take notice of the circle on the floor (click marker) before the movement starts).

    The Character: Move to point action (and what you have in the Movement template) gets close to what I am looking for, but I'd rather not have to set predefined points using markers, but let the player be able to move to whatever point they click on.

  • Switch to First Person movement, and create a new Cutscene with a single Character: Move to point Action. Have it command the Player to move to a new Marker, and check Wait until finish?.

    Place the following script on the Marker:

    using UnityEngine;
    using AC;
    
    public class FirstPersonPointClick : MonoBehaviour
    {
    
        public ActionList onClick;
    
        void Update ()
        {
            if (KickStarter.stateHandler.IsInGameplay () && Input.GetMouseButtonDown (0))
            {
                Ray ray = KickStarter.CameraMain.ScreenPointToRay (Input.mousePosition);
                RaycastHit hit = new RaycastHit();
    
                if (KickStarter.settingsManager && KickStarter.sceneSettings && Physics.Raycast (ray, out hit, KickStarter.settingsManager.navMeshRaycastLength))
                {
                    transform.position = hit.point;
                    onClick.Interact ();
                }
            }
        }
    
    }
    

    Assign the Cutscene in the Inspector's "On Click" field, and run the scene. This will cause the Marker to teleport when the Player clicks on the NavMesh, and then run the Cutscene.

  • Thanks, Chris! The script works. Only thing is that I can no longer click on hotspots in my scene as it seems all clicks are stolen by the new move script. I'm also noticing that if I click on walls in my scene it will try to move my player into the wall and get stuck. I know I can use the "Enforce time limit?" option to get unstuck, but it would be cool if the clicks only responded to clicking on the navmesh so the player didn't have to wait for the time limit to run out before they can move again. Please let me know if this is possible. Thanks!

  • The script should only have an effect when explicitly clicking on collider objects that are placed on the NavMesh layer. Is this true of the walls in your scene?

  • edited January 15

    The colliders for my walls are on the Default layer, but if I change that to the Ignore Raycast layer then I get the desired behavior, clicks respond only clicking on the floor (navmesh).

    However, I do need some colliders to block raycasts by setting them to the Default layer so the player can't click through walls. Is there a way to have these raycasts ignore the Default layer?

    I think this is also why its stealing my clicks when clicking on hotspots since those are on the Default layer too.

  • Try this:

    using UnityEngine;
    using AC;
    
    public class FirstPersonPointClick : MonoBehaviour
    {
    
        public ActionList onClick;
    
        void Update ()
        {
            if (KickStarter.stateHandler.IsInGameplay () && Input.GetMouseButtonDown (0))
            {
                Ray ray = KickStarter.CameraMain.ScreenPointToRay (Input.mousePosition);
                RaycastHit hit = new RaycastHit();
    
                LayerMask layerMask = 1 << LayerMask.NameToLayer (KickStarter.settingsManager.navMeshLayer);
    
                if (KickStarter.settingsManager && KickStarter.sceneSettings && Physics.Raycast (ray, out hit, KickStarter.settingsManager.navMeshRaycastLength, layerMask))
                {
                    transform.position = hit.point;
                    onClick.Interact ();
                }
            }
        }
    
    }
    
  • That works! Thanks, Chris!

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.
Do NOT follow this link or you will be banned from the site!