• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Waka-Takaki · Nov 24, 2018 at 09:53 PM · collision detectioncollider2dtilemapcollisions

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!

circlecollider2d contacts missing

In this screen shot you can see the grid and that every tile is displaying active hexagonal colliders.

circlecollider2d tile map colliders shown

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

screenshot-71.png (400.1 kB)
screenshot-72.png (375.6 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

98 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My OnCollisionEnter says i have 128 Collisions every collision 1 Answer

OnCollision2D never worked 0 Answers

Tile collision by sprite is not accurate with Tilemap Collider 0 Answers

How to stop a bullet (CircleCollider2D) from continuing to move after hitting a wall? 1 Answer

Bug? - Collision with transform size instead of collider 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges