- Home /
OnCollisionEnter Issue...
Ahoy! I'm having an issue detecting a collision driven by an enemy player. Below is the basic set-up:
Player is a static collider tagged "PlayerCollider"
Enemy is a rigged / animated (Cinema4D) import with a sword as a child of the last joint (hand)
Issue: When enemy animation swings sword, the collider (+ the script below) does not detect a collision (rigidbody projectiles seem to detect just fine)
var glassCrackParticle : GameObject;
function OnCollisionEnter( collision : Collision ) {
if(collision.gameObject.tag == "PlayerCollider"){
print("sword hit");
var contact : ContactPoint = collision.contacts[0];
var rotation = Quaternion.FromToRotation( Vector3.up, contact.normal);
var instantiatedExplosion : GameObject = Instantiate(glassCrackParticle, contact.point, rotation);
}
}
Is there something to animated rigs with weapons attached to them don't detect quite right?
Thanks in advance CapnJ
Answer by Ben 14 · Sep 16, 2011 at 12:00 AM
Try adding a RigidBody set to Kinematic to the moving collider. If you don't do that, Unity physics will think both colliders are static and never check for them colliding. Setting the IsKinematic flag of the rigidbody basically tells Unity this collider is moved by script or animation, and to perform proper collision checks on it.
Hmm, that sounds absolutely correct, but making those adjustments in my situation didn't work. But your answer IS correct so I'm going to mark it. Something else that did end up working was to leave the sword as non-kinematic and no-gravity, while turning all of the position and rotation constraints.
Your answer
Follow this Question
Related Questions
Change Direction on Collision 6 Answers
get angular velocity change from collision 0 Answers
Collision with no contact? 2 Answers
script trying to access a null gameobject's collider... can't fix 2 Answers