Forum rules - please read before posting.

Character Spawning on Navmesh

When I bake a nav mesh in Unity, the player sometimes stops spawning on the default player start and just pops to a corner of the navmesh. If I make this corner not walkable, the player just spawns at another corner. How do I correct this issue?

Comments

  • A NavMesh by itself has no collisions.  Please provide more detail in the form of screenshots of your scene and Inspectors involved.

    What is your player prefab?  Does it work if you temporarily replace with the demo game's, Tin Pot?  What if you then manually run an Object: Teleoprt Action to force the player back to the PlayerStart?
  • So the Tin Pot character actually spawns in the right location. I attached screenshots to show the issue. The Object Teleport won't work because there are multiple spawn points in this location, based on the map you exit from. Seems to be an issue with something on my player prefab. Attached to the character I have Nav Mesh Agent, Unity Third Person Integration script, Player (Script), Paths (Script), Third Person character script, and a collider. All should be the default settings mostly, except for the settings changed in the character script.imageimage
  • edited April 2018
    With the Object: Teleport Action - I wasn't suggesting that as a workaround, but knowing if it works or not is important to learn the cause.  Please try it as advised and let me know the results.

    As Tin Pot is fine, this'll be an issue with the fact that its connected to the Unity Third Person Character.  When the character is positioned by AC, the Teleport() method in the integration script is run automatically.

    Currently, this method runs the following:
    navMeshAgent.Warp (transform.position);

    Test removing it, and replacing it with:
    navMeshAgent.Warp (characterAC.GetTargetPosition ());
  • Replacing the code didn't seem to work. Doing the Object: Teleport option did work.
  • Currently, I just set a Check Previous Scene to determine where to teleport the player, but I would love to know how to fix this.
  • It's not a problem I can recreate.

    The Warp function call is necessary when teleporting so that it "resets" at this time.  When a NavMeshAgent warps, it will move to the point on the NavMesh closest to that requested.  If it has trouble finding such a point, it could cause such a behaviour.

    Try replacing the code I mentioned above with:

    Vector3 warpTo = transform.position;
    bool warpSuccess = navMeshAgent.Warp (warpTo);
    Debug.Log ("Warp to " + warpTo + ", Succesful? " + warpSuccess + ". Current position: " + transform.position + ", Target position: " + characterAC.GetTargetPosition ());

    Without manually teleporting, what's the output in the Console when the game begins, and what are the co-ordinates of the PlayerStart and incorrect player position?

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.