RichAI + Recast Graph falls though terrain

It always happens when the AI is climbing a mountain, most of the times it’s able to teleport back on the hill but sometimes there’s the warning “Path Failed : Computation Time 0.00 ms Searched Nodes 0” and the AI keeps falling down. It happens pretty easily if I use root motion but even without root motion I can make it fall though the ground.
I don’t know if this has something to do with the recast graph going under the terrain at some places.

Which movement script are you using?
And do you think you could post a video of the issue?

RichAI + Seeker and it falls through the terrain when its climbing the hill, always happens when using root motion. I can send a detailed video if you give me your email.

I have sent you my email using a PM

Any luck fixing this??

There are some tricks that solve the problem in case someone finds this thread looking for a solution. None of these are the “correct” solution - they’re more like hacks. In my opinion, the correct solution involves tweaking the code for the “Transform.position” movement mode (I think it has something to do with raycasting below the agent into terrain and possibly gravity).

If you have agents with fast speeds and large inclines and you’re not using a rigidbody (or possibly character controller?), your agents will likely fall through the ground.

Here are some options to fix it:

  1. Add a rigidbody. (slows frame rate and doesn’t work with all agent AI types)
  2. Slow your agent down. (may not be acceptable depending on your game)
  3. Slow the whole game down using Time.timeScale. (may not be acceptable depending on your game)
  4. Use only slopes with slight inclines in your levels. (may not be acceptable depending on your game)
  5. Use a character controller? I don’t know if this works or not. (char controllers are slow)
  6. Set your agent height really high (if you have ceilings/overhangs/tunnels, this won’t work)
  7. Write some code that checks each agent and if one is too low, place it back on land. (messy)
  8. Use AILerp (no collision/avoidance at all, paths are unnatural).

I decided to use method 6 for now. I guess if I ever have a level with overhangs or tunnels I’ll have to make some other compromises. Example: On your agent’s RichAI script, set Shape->Height to 8 even if your model’s height is only 1.

I have learned a few new things that I think provide some useful clues as to what is going on:

  1. Objects don’t fall through the terrain when you attach a rigidbody. I haven’t tested character controller, but it definitely happens with or without RVO controller, and whenever you’re using the fallback Transform.position mode.

  2. Slope is a factor. It’s most likely to happen on steep slopes (example: 30 degrees).

  3. It happens on recast graphs as well as grid graphs. It happens with RichAI and AIPath. It does not happen with AILerp.

  4. Timing is a HUGE factor. If you set the agent speed to 5, the agents never fall through the ground. If you set the agent speed to 50, they almost always fall through. If you increase the game speed by using Time.timescale, the agents will fall through.

@Ph0t0n Can you post a screenshot of your agent and its settings?

Also something that shows the scale of the world (how big 1 world unit is).

How much does each agent move in a single frame with the settings you have? If they move more than the radius of the agent per frame (that’s a lot) then you may need substepping to be able to move it correctly. I can show you some code to do this. This is very useful when fast-forwarding a game.

Thanks for helping Aaron,

I can’t upload a screenshot because something is wrong with this website’s size checking. When I attach a jpg that is 1,200kb, an error pops up saying the maximum size upload size 16,384 kb.

The red arrow points at a unit cube that is 1mx1mx1m (you might have to zoom in to see it). The terrain resolution is 500x500.

I have tried 20+ different combinations of agent types/graphs/tweaks. The only configurations I’ve consistently gotten to keep from falling under high speeds are ones with AILerp and ones with rigidbodies. My agent radius size is about 1.5m. Below is the configuration I’m currently using - it seems to provide the best results for now. When I removed the rigidbody and set the agent height on AIPath really high (8m), it worked great in normal play mode, but in fast-forward, the agents all started dropping underground again so I had to go back to using a rigidbody.

What you’re describing sounds like it fits the symptoms of what is happening. I would love it if you could send some substepping code - lclemens@gmail.com . Thanks!!

If you have a very high time scale you can do something like this to make it run multiple movement calculations per frame.

IAstarAI ai;
public void Awake () {
	ai = GetComponent<IAstarAI>();
}

public void Update () {
	// Make the AI not do any movement by itself
	ai.canMove = false;
	// Run the movement code multiple times per frame
	int timeMultiplier = Mathf.Round(Time.timeScale);
	for (int i = 0; i < timeMultiplier; i++) {
		Vector3 nextPosition;
		Quaternion nextRotation;
		ai.MovementUpdate(Time.deltaTime / timeMultiplier, out nextPosition, out nextRotation);
		ai.FinalizeMovement(nextPosition, nextRotation);
	}
}

This may not work that well with local avoidance though, as that still runs at the same frame rate.

See also these topics: