- Home /
Character Controller's Collider Restricting Other Colliders
Hello;
My game has AI opponents that use character controllers. I set the height of the collider so that the model's head mesh is out in the open. Then I proceed to add a mesh collider to the head mesh and attach a custom headshot script. The script works perfectly fine when attached to a foreing object, but when it's attached to the head mesh, the Character Controller's collider seems to block and/or work against the mesh collider of the head mesh. I tried using physics.ignorecollision with negative effect. Can someone advise me on how to work around this problem?
Thanks in advance;
-Jon
Answer by scarletsnake · Oct 27, 2012 at 04:06 PM
Did a workaround of sorts;
#pragma strict
var AIBody: Transform;
var AIHeadBone: Transform;
function Start () {
}
function CanDie ( damage : float) {
damage = 100;
AIBody.GetComponent(typeof(AI)).CanDie(damage);
}
function Update () {
transform.position=AIHeadBone.transform.position;
}
Add this to a sphere about the size of the character's head. Any other suggestions are still welcome, but this works and really doesn't hinder the performance at all. Colliders and rigidbody working perfect as well.
Your collider usually don't hate to be a normal collider. Just tick the isTrigger checkbox and use the OnTriggerXXX messages ins$$anonymous$$d of the OnCollisionXXX messages. When you use a raycast to shoot, nothing has to be changed since you can raycast against triggers as well.
Yeah I've tried that as well, but the Character Controller will still overlap any sort of raycasting to a child of the game object.