I’m having trouble figuring out how to make it so that my player team has local avoidance enabled for it’s own units, but it’s disabled for enemy units so they don’t push them out the way
My code looks like this, however when I have it set like this the player units and enemy units just walk through each other.
I’m using FollowerEntity with a recast graph. All my units have a box collider in the root object. I feel like this is extremely obvious but I’m overthinking it. I was using Unity Navmesh previously and units would collide with each other so I don’t think it’s related to my unit gameobject.
the player units can no longer move through enemy units, however the enemy units will push the player which is what I don’t want. (and visa versa if I set it on the enemies layers)
Also if I set them both to have each other on the collidesWith layer they all just walk through each other
I was surprised you deleted your post. I could still see it in my email so I tried what you suggested and you were right, the collidewith layers were not setting in the managed state, however when I set them manually in the editor the same thing happens as when I set them via my code snippet above I thought you had solved it. Thanks though
FWIW though my code block does set them properly in play mode
Oh haha, I second guessed myself because I misread the problem.
On third reading I think I understand the issue. When you used Unity Navmesh you were relying on the physics to stop them. The difference with FollowerEntity is that you don’t have a collider and rigidbody on the entity doing pathfinding, you have them on the gameobject following that entity. The gameobject’s position is being overwritten by the entity every frame, so it’s physics aren’t stopping it.
One solution is to figure out how to add the collider and rigidbody to the Entity generated by the FollowerEntity. It should work if entity physics runs after pathfinding.
The other and probably more performant is to not use physics collisions and add some logic to stop when it gets close enough to an enemy. Simplest would be spherecast for enemies, if there is one set the destination to positive infinity.
then the player units will try to avoid the enemy units, but not vice versa. So the player units will not be able to move the enemy units out of the way.
The enemy units will be able to move the player units out of the way, though.
Ah okay, doing a spherecast was easy enough I guess I just misunderstood the documentation and assumed this was a feature based on how I interpreted the collidesWith snippet in the docs.