x


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

more ▼

asked Sep 15 '11 at 10:30 PM

Capn J gravatar image

Capn J
3 4 4 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Sep 16 '11 at 12:00 AM

Ben 14 gravatar image

Ben 14
448 7 8 18

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.

Sep 16 '11 at 01:07 AM Capn J
(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:

x2497
x653
x227
x48
x17

asked: Sep 15 '11 at 10:30 PM

Seen: 763 times

Last Updated: Sep 16 '11 at 01:07 AM