- Home /
Strange OnCollisionEnter behavior, returning wrong collision object?
I can't seem to figure out why I'm getting the following behavior...
I have a Prefab (call it Bomb). It's on a layer EnemyFire. It has a rigid body and a collider (no trigger), both on the parent, and the geometry is a child of that prefab parent.
Attached to the parent prefab is a script (bombMover).
I also have terrain - which is on the Terrain layer. The physics grid has collisions enabled for Terrain and EnemyFire layers to interact.
When the bombs strike the ground, OnCollisionEnter is getting called on the bomb prefab script, but when I use this in OnCollisionEnter: Debug.Log("Bomb Hits: "+collision.name);
The output is "Bomb Hits: Bomb" --- it's saying it hit itself, not the real object it hit.
When the bomb hits the player object, which is on the Player layer, the collision is also triggered, and again, the bomb says it hits the Bomb object.
Any idea what might be causing this?
Answer by tanoshimi · Jul 07, 2014 at 08:24 PM
The collision class doesn't have a name
, so I'm surprised you're getting anything at all. What happens if you replace it with:
collision.gameObject.name
?
That did the trick. I don't know what that the first log was pointing to, but your suggestion worked.
Your answer
Follow this Question
Related Questions
Ragdollize kinematic rigidbodies 0 Answers
Trouble with OnCollisionEnter and Exit 1 Answer
Updating Velocity for a Rigidbody Collision 1 Answer
moving at certain circumstances 1 Answer