Support Forum

Spherical navmesh with constraint

Hi,

I’m using the beta version (4.3.32 and also tried 4.3.31) so I can use the AIPathAlignedToSurface component on a custom navmesh that’s spherical. I’d like to use ‘Constrain Inside Graph’ option but when I enable that, the agent just falls off the world or slides to the bottom of the world. If I disable the gravity, the pathfinding works nicely but then the agent is doesn’t get rotated properly.

Still having this issue in 4.3.34

Take a look at this thread that track how we solved this issue + moving sphere:

This is how we clamp to the sphere, our radius is 5.0 (hence the magic number).

        protected override Vector3 ClampToNavmesh(Vector3 position, out bool positionChanged)
        {
            // This code clamps the AI to the sphere of radius 5.0f
            positionChanged = false;
            // Normalize position then scale to radius of sphere
            Vector3 newPosition = Vector3.Normalize(position) * 5.0f;
            if (newPosition != position) positionChanged = true; // not sure what this does
            //Debug.Log(position.ToString());
            return newPosition;
        }

Unfortunately that solution won’t work for us since it’s not perfectly circular.

Is your navemesh moving? If not the Example19_Moving should work.

The navmesh isn’t moving. The example also has the same issue, as soon as I enable the ‘Constrain Inside Graph’ option, the movement breaks. Seems like that option also enables some global gravity.