x


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?

more ▼

asked Nov 19 '09 at 01:57 AM

MadCow gravatar image

MadCow
39 2 2 6

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.

Oct 10 '10 at 12:49 AM Loius
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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 http://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.

more ▼

answered Nov 19 '09 at 07:23 AM

Sam Bauwens gravatar image

Sam Bauwens
145 3 3 12

(comments are locked)
10|3000 characters needed characters left
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.

more ▼

answered Oct 09 '10 at 11:09 PM

rpl oye gravatar image

rpl oye
65 5 5 15

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2488
x1866
x1041

asked: Nov 19 '09 at 01:57 AM

Seen: 4916 times

Last Updated: Nov 19 '09 at 01:57 AM