I want my enemies are not collide with each other.
So I set like this,
function Start(){
var enemies = GameObject.FindWithTag("enemy");
Physics.IgnoreCollision(enemies.transform.collider, collider);
But error says,
Scene::setShapePairFlags: The two shape references must not reference the same shape.
UnityEngine.Physics:IgnoreCollision(Collider, Collider, Boolean)
UnityEngine.Physics:IgnoreCollision(Collider, Collider, Boolean)
UnityEngine.Physics:IgnoreCollision(Collider, Collider)
orcscript:Start() (at Assets\Scripts\Enemy\orcscript.js:50)
[\unitystuff\proj\external_sources\physx\novodex\SDKs\Physics\src\NpScene.cpp line 1250]
Why? and how to set right?
I tried with 2 of enemies and they both has capsule collider.
What game object or objects is that script associated with?
It looks like what you’re trying to do is find all of the game objects with the tag ‘enemy’, and disable collision between each of them and the current enemy (the one with which the script is associated).
However, there’s a couple of problems here. First, FindWithTag() only returns one game object, not all game objects with that tag. And in any case, the expression ‘enemies.transform.collider’ doesn’t do what you think it does (it looks like you’re expecting it to return a collection of all of the colliders associated with all of the enemies in ‘enemies’, but even if ‘enemies’ were an array - which it’s not - it wouldn’t work that way).
What you need to do is use FindGameObjectsWithTag() to acquire an array of all of the objects with that tag. Rather than putting this in the enemy Start() function (which I’m assuming is where this is), I’d probably put it in a ‘setup’ game object so that you can disable collision for all unique pairs of enemies in one go.
The error is probably because at some point you’re trying to disable collision between the enemy and itself, so you’ll need to test for this case and skip over these pairs.
To keep it simple, we won’t worry about processing pairs redundantly. With that in mind, here’s some code (C#, but you can easily convert it to UnityScript):
foreach (GameObject go1 in gos) {
foreach (GameObject go2 in gos) {
if (go1 != go2) {
Physics.IgnoreCollision(go1.collider, go2.collider);
}
}
}