- Home /
Cannot detection collision
Greetings, I'm scripting a sword hit to apply damage. The problem is that Unity does not detect any collision.
Here's the test script,
var damageAmount = 20;
var isHitting : boolean = false;
function OnCollisionEnter (collision : Collision) {
isHitting = true;
if (collision.gameObject.GetComponent(Tagger).canBeHit == true){
collision.gameObject.SendMessage("applyDamage", damageAmount, SendMessageOptions.DontRequireReceiver);
}
}
For some weird reasons, the isHitting boolean does not turn true. Both my object that have the script and the one I hit have a collider.
Does at least one of the colliders also has a non kinematic rigidbody attached? $$anonymous$$aybe the problem relies on the absense of it.
Answer by Statement · Dec 15, 2011 at 09:09 AM
Try adding a rigidbody to your object, unless you have. Just moving a collider around won't trigger collisions. It has to be a rigidbody on either end of the collision. If you don't want it affected by physics, set it to kinematic in the inspector. This should enable your collision callbacks.
Erf, I forgot it on the sword tip. Can't believe I forgot that. Thanks.