- Home /
Collisions: do they need two rigidbodies?
I'm struggling to get Unity's collision system working, and having trouble understanding it. The way I have it, I have two GameObjects, both with colliders, and one with a rigidbody (called the "Enemy"). Now, in the game I detect whether a key has been pressed and use it to iTween rotate the other object, without the rigidbody (called the "Weapon"). But there's a problem--on both the objects I've tried to use an OnCollisonEnter function. Later, I'm going to use this to send messages, but for now, it's just supposed to print that a collision has occurred.
When the two objects collide, nothing prints. The Enemy prints when it touches the ground after spawning, but the Weapon never prints anything. Do both objects have to be rigidbodies? Is there any other, simpler way of detecting collisions between a melee weapon and a character?
Answer by insominx · Jul 20, 2012 at 11:16 PM
The "Collision Action Matrix" will tell you which interactions will result in a message callback to your script. Check what types the 2 objects are and look them up in the table. You may need to add a rigidbody component to one of your objects or make sure the rigidbody is on the same object as your script.
For a video walkthrough and a demo, see here: Unity Tips and Tricks: Physical Interactions with Collisions and Triggers.
Answer by flaviusxvii · Jul 27, 2011 at 04:49 AM
The "Collision Action Matrix" towards the bottom of this page is what you need.
http://unity3d.com/support/documentation/Components/class-MeshCollider.html