RichAI in complicated scene frequently falls through the floor!

I’m using the complicated asset store “Demo1” from the “Underworld: Cave environment” for testing.

My RichAIs fall through the floor (fairly frequently)! This does not happen with a Unity Navmeshagent + Unity Navmesh.

My AIs are simple capsules, collider removed, with a RichAI component and a simple test script that changes the RichAI target when the AI is within a short distance of the current target. The AI does not need to get near a target to fall through so I think that the problem is entirely while the object is under the control of RichAI. I only set the location of the capsules when I spawn them. It can take a while before one drops through but it will happen. Spawning one capsule a second (going to a random target in the scene), within about 45 seconds I saw 6 that fell through.

Is there a fix for this my end?
If there’s no fix my end can you let me know when a fix will be available please?


The RichAI script uses physics raycasting to determine where the ground is. Are you sure the ground is covered by colliders at all locations?

I’ve looked at the mesh and I believe that it is complete with all expected colliders. (Also, if there were gaps, somehow Unity manages to cross them). Watching the AIs move it seems a bit hit & miss as to if the AI will fall through or not. Prior to testing A* I had a lot of physics in the scene with things that bounce off the walls/floors etc. and they never went through, (or the Unity Navagents).

Looking at the RichAI code, (I think that) the collision uses a single ray line segment to determine if there’s a hit. I wonder if when you get to a step/rock/lump etc. in the ground that it is possible by moving forward you end up with the ray now going from fully above the ground to fully below it, (although the inclines appear much smaller than something that I would have thought could be a problem. I also imagine cases where there’s dip which will allow your AI to drop and possibly take the ray line below the height of (say) a horizontal collider. If this is part of a collider (for say, the top of a step) and the next frame takes the ray line segment fully past the vertical collider on the edge of the step then you are in trouble, you’re now fully below the step collider with nothing left to hold you up.

On the intermittent nature of this, I suspect the algorithm for the physics could be tweaked to cope; Because there is no test of the gap between the ray line from the previous frame and the new one, I guess you would ideally need something covering the whole area that the ray has traversed in order to be certain of catching all cases.

In addition to the existing colliders in the scene I’ve added angled planes under step areas (which is typically where problems occur). Stuff still falls through and with the planes there, which also have colliders and are marked static for just about everything, the RichAI should pick them up (although they should not be needed). I am trying to get a meaning full debug shot to show that the problem is with the data for the raycast. At the moment I am storing the last failed raycast after a good one so that when things fall through you can see that the raycast bounds are not calculated quite right for this scenario.

The following shot shows the last raycast that failed after the last good one.

Above the grey area (a plane with collider) you can see various capsules with RichAI. One has my yellow debug ray showing.

Below the grey area you can see a selected capsule with RichAI that has fallen through. You can see the last raycast that failed after the last one that got a hit, (but the capsule has continued to fall). As you can see, that raycast is not where it needs to be by quite a way.

I recommend that you also try this on a bump inclined area (or better still grab a copy of the scene I used). I notice that the AIs seem to make an effort to get up the slope, nice but I wonder if this issue stems from the physics side of that. Watching RichAIs go up & down the slope (and other areas) I can see the repeat fails of the raycast which normally stays above where it needs to yet the AI sometimes continues to slip down, usually recovering. That might be a clue for you.

I’m out of way time this evening so I hope, Aron, that you will investigate this as I really have high hopes with the speed of A*. Please let me know your thoughts.


Sorry for all the problems this has been causing for you.

So I think the main issue you are having is that the RichAI uses (by default) a single ray to detect the ground.
This is done for performance (since CharacterControllers are horribly slow in comparison).
However fear not, the RichAI script supports multiple ways of handling movement.

In particular, if you attach a character controller to the GameObject that the RichAI is attached to, it will automatically switch to using that instead of the raycasting + transform code. This will hopefully give you a lot more stable behaviour.
(and hopefully it is not affected by the same possible bug mentioned below).

Still, I think the raycasting code should be able to handle your scenario, and since you have found that the raycast is off, there might be a bug in the code. Is there a possibility that you could share your project with me so that I could take a look at it and try to replicate it?

Please refer to my reply in this forum entry: