Forum rules - please read before posting.

Unity Navigation issues

edited February 2016 in Technical Q&A
Hello!

I have created a Unity Navigation and that seems to be working for the most part. The only issue I am having is when I click on parts of the scene, during gameplay, that are not on the Unity Navigation, the Player still tries to go there. In this screenshot, it actually is trying to go to the table chair ( which is off the floor )

image

All items have been set to Ignore Raycast so I'm not sure what is going on.

What I am trying to accomplish is that I want my player to only move to the the Unity Navigation parts ( the blue parts ) and not the rest of the room. If I have to make a Mesh Collider for this to happen, I can if need be.

Using 1.50g

Thanks!

Comments

  • edited February 2016
    Currently, the baked NavMesh has to match up as closely as possible to any colliders that are on the NavMesh layer - because it's the colliders that record the "intended" position.

    This is why NavMeshSegments are available: if you just rely on those, it's easier to get a 1:1 match.  But yes: switching to Mesh Collider would solve the problem.
  • You can always copy the baked navmesh data and turn it into a mesh collider. Is easy, works great.
  • Teshla:

    That sounds exactly what I need to do. Do you mind providing me an example about how to go about that?


  • All:

    Teshla comment led me to this link:

    This has code to export the NavMesh as a obj and it solved most of my issues.

    Teshla, I would still like to know your workflow if you do not mind, but this code snip did work for me.

  • Hey, basically I add two things:

    1. I create a GameObject in scene which has "Mesh Collider" component from Unity and "Nav Mesh Segment" from Adventure Creator. Mesh collider component has no material or mesh.

    2. Also have a script that does this:

    public class MeshExporter : MonoBehaviour {

        public MeshCollider meshCollider;

     void Awake () {
            NavMeshTriangulation tri = NavMesh.CalculateTriangulation();
            Mesh mesh = new Mesh();
            List<Vector3> verts = new List<Vector3>();
            for (int i=0; i<tri.vertices.Length; i++) {
                verts.Add(tri.vertices[i]);
            }
            mesh.SetVertices(verts);
            mesh.SetIndices(tri.indices, MeshTopology.Triangles, 0);
            mesh.RecalculateBounds();
            meshCollider.sharedMesh = mesh;
        }
    }

    The public variable of MeshCollider in the script above is set to the collider I described in point #1.

    Also you have to execute the script earlier than the default execution order. Either that or figure out a place to put the scripts logic inside AC scripts themselves, but I found that the option with separate script and modified execution order gives you far less problems when you need to update AC itself.

    When I was looking for a solution for this problem I think I came across the same thread that you mentioned and based my script off of info in it.
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.