- Home /
CharacterController:disable character-to-character collision
I was wondering if there was a way to disable character collision when using CharacterController.
I still want all other collision detection (terrain etc) but when colliding with other CharacterControllers, I'd like that collision ignored.
Any idea?
If using unity 3, you can put all CharacterController objects on their own layer and use Edit->Project Settings->Physics to have that layer ignore collisions with itself.
Answer by Sam Bauwens · Nov 19, 2009 at 07:23 AM
You can make a script that you attach to a single game object (for which there's just going to be one instance) and you put the following code in the Start
function of the script :
void Start() {
UnityEngine.Object[] characterControllers = GameObject.FindObjectsOfTypeAll(typeof(CharacterController));
System.Collections.ArrayList existingCCColliders = new System.Collections.ArrayList();
foreach (CharacterController charController in characterControllers)
{
Component[] colliders = charController.GetComponents(typeof(Collider));
foreach (Collider collider in colliders)
{
foreach (Collider existingCollider in existingCCColliders)
{
Physics.IgnoreCollision(collider, existingCollider);
}
}
}
}
Now there are probaly bugs in this code.It's just the logic, I haven't tested it. But the idea should work. and maybe you'll have to replace the arraylist by some other type of collection as I don't remember if arraylists are supported in Indie.
Answer by rpl oye · Oct 09, 2010 at 11:09 PM
function Start() { ignoreCollision("Player"); }
function ignoreCollision(tag: String) { var objects = GameObject.FindGameObjectsWithTag(tag); for (o in objects) { if (o.GetComponent("Collider") && o != gameObject) Physics.IgnoreCollision(collider, o.collider); } }
just editing the post above me.
Your answer
Follow this Question
Related Questions
How to stop first person player from walking through animated door 1 Answer
Voxel engine physics 3rd person character controller 1 Answer
early collision above character controller 2 Answers
gameobject destroyed on collision with character 3 Answers
How can i make particles push back the player on collision? 1 Answer