- Home /
Collider2D overlap with tiles in Tilemap and remove tiles
I am working with Unity and I have a Tilemap filled with tiles. At a given point in time, I create a Collider2D in the scene with a specified width and height. What I need to do is obtain the list of tiles within the Tilemap that are overlapped by the Collider2D object that I just created.
Collider2D[] results = new Collidear2D[16];
int count = rb2d.OverlapCollider(contactFilter, results);
for (int i = 0; i < count; i++)
{
Collider2D result = results[i];
Tilemap breakableMap = result.gameObject.GetComponent<Tilemap>();
breakableMap.SetTile(breakableMap.WorldToCell(..........), null);
}
With the above code, I can determine the Collider2D objects that I am overlapping. However, in order to remove a tile from the Tilemap, I need an actual Vector3 coordinate that indicates some point of contact between the region of overlap between the two colliders.
My question is, in regards to this question, is this current approach the ideal approach? If so, what can be done to easily retrieve the coordinate of the overlapped tile so that it can be removed?
Answer by Nikola7007 · Jul 17, 2018 at 12:07 AM
Might GetContacts() work?
https://docs.unity3d.com/ScriptReference/Collider2D.GetContacts.html
Your answer
Follow this Question
Related Questions
How do I get collisions between Tilemap Collider 2d and a Kinematic Rigidbody 2d? 1 Answer
[Game like Pong] Trying to change direction with a boxcollider 0 Answers
Any way to visualize Overlap methods without using Gizmos? 0 Answers
tilemap collider2D is it possible to "walk" inside composite collider (pictures to explain) 2018.1 0 Answers