2D Collisions aren't detected. What to use for tiles?

Hi,
I want to make simple game based on tilemap. I’m trying to detect collision between Player (this black circle :P) and tiles (white and red squares).

Player is a sprite and tiles are “quad” (I really don’t know what’s this, I’ve tried to use plane, but in 2d view it isn’t visible (maybe that’s the problem)).
Both of them have component “Box Collider 2D” and Player has also “Rigidbody 2D” with “Is Kinematic = true”.

Code:

function OnCollisionEnter(collision : Collision){
	Destroy(collision.gameObject);
	Debug.Log("Booom");
}

When Player is on the tiles nothing happens (but it should destroy tiles )

2 Answers

2

So, I found the answer (thanks for Patrick from Google+)

The problem was: in 2D games OnCollisionEnter doesn’t work. When you want to detect collisions in 2D game you have to use OnCollisionEnter2D.

Good to know, thank you.

I think you need to add a rigidbody to the tiles also and set:

Rigidbody2D.isKinematic = false;

I don’t think the colliders do anything by themselves.

and how can I disable only gravity of Player? Now I use isKinematic=true but it reportedly disable other forces too (which are necessary for me)

Physics2D.gravity allows you to globally modify gravity. Physics2D.gravity = Vector2.Zero; If you only want to disable gravity for a single rigidbody: Rigidbody2D.gravityScale = Vector2.Zero; If your game has no gravity, I suggest you use Physics2D.gravity.

Knock, knock. How are things going?

so, yeah I found the answer to my question. I posted it here, but it have to be checked by moderator before it appear here ;)

Your answer wasn't helpful but thank you for trying :P