Colliding two gameobjects moved by RichAI


I’m having trouble detecting collision between two enemies that are moved by RichAI on a recast graph.
The goal I’m trying to reach is: there are bunch of enemies in the level, they chase the player, move around him, run away, etc. I need them to never go through each other and thus collide.
I looked around the forum before posting this but couldn’t find anything relevant. I found RVO local avoidance but I’m not sure that’s what I should be using.

I tried putting rigidbodies on them and then collision happens obviously, but if I leave any constraints unchecked they start sliding around when they collide. If I check all the constraints then they don’t detect collision anymore (or maybe they do, I haven’t checked the log, but they don’t affect each other’s movement anyhow). Using isKinematic also doesn’t seem to work.

What adds to the problem is that I’m not sure how RichAI moves the object it is on, since there’s no character controller or rigidbody on it and I can’t find its movement code; and that just makes it harder for me to find a solution to this.

Both enemies are on “Enemy” layer which is set to interact with itself in Unity’s Physics settings.


If you do not attach a CharacterController to the RichAI script then it will simply modify the Transform.position property. The easiest way to get collision working is to simply attach a CharacterController. The RichAI script will use it automatically it if detects that one is attached.

I’m getting a weird behavior with character controllers. My A.I. moves slower and rotates very slowly too. It doesn’t seem to function properly. I tried setting RichAI’s MaxSpeed and Acceleration much higher and it seems to function more or less properly when the A.I. is around player, as in it rotates with enough speed and seems to follow the player well, but it acts weirdly when spotting the player from afar; it comes at very high speeds and overshoots the location.
Bottom line is its movement is inconsistent no matter what I do; and besides I’d rather not use character controller at all since you recommend against it in the documentation on the account that it’s relatively slow.

I also tried putting rigidbody on it with a heavy mass (100) but it still slides as if it doesn’t have any mass when player collides with it. I tried bunch of variations of freezing rotation and position, turning off isKinematic, etc. but nothing gave me the desired effect.

What’s the most optimal way to move it so it collides with others?
I think I’ll eventually want my enemies to also avoid each other instead of just mindlessly colliding, so maybe RVO should be used? Although I couldn’t find a clear explanation of what it actually is, only documentation that didn’t explain much.

Please help : |

Any advice on how to progress with this?


Sorry for the late answer.
CharacterControllers are slow if you want to use it on a lot of characters, but if you only have on the order of say 10 units, then it’s not a problem. Ultimately you should profile it and see if it is a problem for your game.

Do you have the slowWhenNotFacingTarget option enabled? In the current version that will in some cases not allow it to turn as quickly as it should and may make it a lot worse at stopping at the precise target point. Try to disable it if you have it enabled. (I have done some improvements to it in my dev version though).

If you use RVO you do not need to use a CharacterController though (at least if you only want to avoid collisions with other agents, if you want it to collide with other obstacles in the world you still need a character controller). If you want to use RVO you should use the current beta version though since that has some important updates.

RVO is a local avoidance technique which aims to ensure that the characters do not move with a velocity that will put them on a collision course with another agent. The RichAI agent has support for that component so you should be able to just attach it to the same GameObject and it will work. You will also need a single RVOSimulator component in the scene.

I’m going to have more than 10 enemies at a time, so if there’s any other faster option, I’d rather do that.

I tried disabling “slowWhenNotFacingTarget” as well as “preciseSlowDown”, none made any difference, if anything, it seemed that disabling slowWhenNotFacingTarget made it worse, but it might just be me. What happens is that A.I. starts rotating very slowly and even if i’m right next to it, it seems to be just drifting around me aimlessly. I can shoot a video and link it here if that’ll help.

I don’t think I need RVO at this point, I might just make the enemies change direction when they collide with each other. I tried throwing in the RVOSimlator before and putting RVO on my A.I. and it gave me bunch of errors. Then I tried looking up any tutorials and failed : /

I’d rather just focus on proper movement and collision for now and if I’ll need the RVO later, I’ll post here. For now all I want is for my A.I. to move the same way it moves currently (without character controller) and to collide with each other (so that I can detect those collisions and do something when they happen).

Is there any way we can speed fixing this up? I can screenshot my inspector or link to gameplay video. If you made any changes to the project I can download the newest one. I just need to get this working asap.

If you would show a video of the issue that would be great.

Here’s a video of me showing the current movement, the movement with character controller, and the movement with a rigidbody. In the beginning, the collider that I mention is used to detect player’s bullets, not collision with each other (as they don’t have rigidbodies yet).


That looks very strange indeed.
I have sent you a PM with a download link to the latest dev version, I have done some extensive changes to the RichAI script there and I could not replicate the results you were seeing with it. I think it should upgrade cleanly, but I recommend you make a backup of your project just in case.

I merged it and it throws some errors. Does this image tell you anything? I’m trying to fix it now.

Where do you call that method? (the GetPointsOnNodes method)

I’m calling those on some of my enemy types.

The code on one of them is this:

void GetEscapePath(Path p)
	ConstantPath cpath = p as ConstantPath;
	List<GraphNode> nodeList = cpath.allNodes;
	List<Vector3> pointList = PathUtilities.GetPointsOnNodes(nodeList, 25, 10);
	debugSpheres = pointList; ////////////////////// FOR DEBUG PURPOSES, REMOVE WHEN DONE /////////////////////
	Vector3 farthestPoint = GameManager.instance.player.transform.position;
	for (int i = 0; i < pointList.Count; i++)
		if (Vector3.Distance(pointList[i], GameManager.instance.player.transform.position) > Vector3.Distance(farthestPoint, GameManager.instance.player.transform.position))
			farthestPoint = pointList[i];

	seeker.StartPath(transform.position, farthestPoint);

I removed those enemies who call this method and it still doesn’t work. Here’s a screenshot where there’s only one enemy that’s just supposed to move towards the player when in range

it looks like the Pathfinder doesn’t work, the one which has a recastgraph on it. But I checked and it’s enabled so not sure what’s bugging out yet.

here’s how my AStarManager looks when the game’s running

Ok. So for the first error it looks like your “nodeList” variable is empty, that’s why it throws that error.

In your last screenshot I also see a message saying that the OnPathComplete method threw an error, is that something you could investigate?

When the game’s running, I can’t see the AStarPath’s raycast graph generated. Like the blue stuff on the ground in this screenshot. Maybe that’s the core of these errors?

That’s odd. Try to click on the blue “i” button at the top of the graph inspector. It should say how many nodes there are in the graph.

Nodes: 0
Walkable: 0
Unwalkable: 0

As I said, the raycast graph doesn’t seem to be generating and all these errors stem from there I think. Even if I press “Scan” when the game’s running, it doesn’t generate the navmesh

Are you using static batching for the scene? (I think it should have logged an error about that if that was the case, but just in case it didn’t).

Oh. And why does your recast graph have a zero height? (see “size” field).

No, I don’t think I’m using static batching. Also, doesn’t my size Y say 5.96?