- Home /
CircleCollider2D is not registering collisions with some tiles in a TileMapCollider2D
I'm making a tile based game that uses Grid > Tilemap with cell layout as Hexagon.
The player can move a certain distance based on movement level. My plan is to highlight valid movement spaces in green and invalid in red. To do this I've got a child GameObject called MovementRange that has a CircleCollider2D attached with it's radius matching the player's movement level. All settings as default.
The TileMap uses a TileMapCollider2D. As each tile on the grid is smaller than the actual grid hexagon this means that each tile is separated by a gap. The TileMapCollider2D correctly assigns each tile a hexagonal collider. All settings as default. The tilemap also has a Rigidbody2D set as Kinematic and Use Full Kinematic Contacts checked.
This is the function used to highlight the tiles in range:
void HighlightCellsInRange(Collision2D collision)
{
Vector3 hitPosition = Vector3.zero;
ContactPoint2D[] contacts = new ContactPoint2D[100];
int contactCount = collision.GetContacts(contacts);
for (int i = 0; i < contactCount; i++)
{
Vector3Int tile = _tileMap.WorldToCell(contacts[i].point);
_tileMap.SetTile(tile, _greenTile);
_tilesInRange.Add(tile);
}
}
This works correctly for any tile that a collision is registered for. The problem is that some tiles don't register collisions (and others have multiple collisions).
Here are some screen shots where you can see what's happening:
I have generated gizmo spheres at all of the collision contacts returned. The circle collider is selected so you can see that clearly there are missing tile collision contact points. There's 6 missing in the very center of the circle collider!
In this screen shot you can see the grid and that every tile is displaying active hexagonal colliders.
I've tried changing the settings on the circle collider and the tilemap collider but I can't understand why some of the collisions are not registering.
Any advice would be appreciated. Thanks
Answer by Waka-Takaki · Jan 20, 2019 at 08:35 PM
I reported this as a bug to Unity. They have submitted it as a bug report to the team. As it stands it seems collision with individual tiles with TilemapCollider2D are not reliable.
Your answer
![](https://koobas.hobune.stream/wayback/20220612182716im_/https://answers.unity.com/themes/thub/images/avi.jpg)