Forum rules - please read before posting.

Mesh Collider: Pathfinding Problems.

Hello again,

I'm having some problems with Mesh Collider Pathfinding.

  1. The player walks out of the Mesh Collider and crosses over "empty" space to find the target.
  2. The Pathfinding does not use the most direct route and makes unpredictable detours.

I've created the Mesh in Blender. It is just a plane and enabled read/write after being prompted to do so.

  1. Is there a way to limit the distance for pathfinding? So that the user can not click at the end of the map and watch the player make the whole way?
  2. Is there a way to set borders to the mesh, so that the player keeps his distance from the edges?

Thank you all

Comments

  • The player walks out of the Mesh Collider and crosses over "empty" space to find the target.
    The Pathfinding does not use the most direct route and makes unpredictable detours.

    Check that the mesh's faces are all facing the same way. However, it may be that the mesh itself is too complex for the algorithm - Unity's built-in Navigation feature is the recommended method for 3D scenes.

    You can use your custom mesh as the basis for the baked Unity NavMesh by marking it as "Navigation Static" - if you reduce the Agent Radius in the Navigation tab, it'll occupy the same space as the mesh. A tutorial on this topic can be found here.

    Is there a way to limit the distance for pathfinding? So that the user can not click at the end of the map and watch the player make the whole way?

    You can hook a custom script into the OnPointAndClick custom event, which provides the array of points to traverse, and then modify those points to all be at the Player's position:

    using UnityEngine;
    using AC;
    
    public class LimitPointAndClickDistance : MonoBehaviour
    {
    
        public float maxDistance = 10f;
    
        private void OnEnable () { EventManager.OnPointAndClick += OnPointAndClick; }
        private void OnDisable () { EventManager.OnPointAndClick -= OnPointAndClick; }
    
        private void OnPointAndClick (Vector3[] pointArray, bool run)
        {
            if (pointArray.Length == 0) return;
            Vector3 finalPosition = pointArray[pointArray.Length - 1];
            float finalDistance = Vector3.Distance (finalPosition, KickStarter.player.Transform.position);
            if (finalDistance > maxDistance)
            {
                for (int i = 0; i < pointArray.Length; i++)
                {
                    pointArray[i] = KickStarter.player.Transform.position;
                }
            }
        }
    
    }
    

    Is there a way to set borders to the mesh, so that the player keeps his distance from the edges?

    The NavMesh itself needs to be thinner. If you use a baked Unity NavMesh (see above), you can increase the Agent Radius to increase the margin between the edges.

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.