- Home /
2D Collision Between Two Objects
I've been reading around for hours now and I can't figure this out. I've got an asteroid with a kinematic rigid body and a circle collider. I've got a ship that rotates, upon pressing space, it creates a Laser(Clone). The laser is a prefab, which also has a kinematic rigid body and a primitive collider. In the asteroids script, I have this:
function OnCollisionEnter2D(hitbylaser : Collision2D){
if(hitbylaser.gameObject.name == "Laser"){
Debug.Log("hit");
}
I've tried changing "Laser" to "Laser(Clone)" but that doesn't work. This is kind of the most important aspect of the game too. Right now I just want the log to tell me it hit. When it does I'll add the explosion and destruction of the asteroid.
Answer by robertbu · Feb 25, 2014 at 04:18 AM
If you have isKinematic set, then you won't get collision events. To start, figure out if you are getting any kine of collision. Just inside the OnCollisionEnter2D(), put:
Debug.Log(hitbylaser.collider.name+", "+hitbylaser.collider.tag);
This will tell you if OnCollisionEnter2D() is firing at all.
That was it. God bless you. After removing the kinematic, I put gravity at 0, and changed Laser to Laser(clone) like mentioned above.