Hello Guest

Author Topic: Cannot Get Raycast to Hit Using Tilemap Mesh Collider  (Read 8788 times)

mark

  • Newbie
  • *
  • Posts: 7
    • View Profile
Cannot Get Raycast to Hit Using Tilemap Mesh Collider
« on: April 21, 2014, 10:37:56 pm »
I've spent a couple days on this, tried everything, I can't figure out what I am missing here. 

I create a tilemap fine, and the mesh collider on the chunks looks good in the editor window, but when I run the game I cannot get a hit with a raycast.  If I manually put a box collider on the chunk, however, I have no problems getting the raycast to hit.

Not sure where to start.  In the sprite colleciton, I've tried every possible combination of collider settings.  Also tried all combinations on the generated mesh collider.  Still no luck.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Cannot Get Raycast to Hit Using Tilemap Mesh Collider
« Reply #1 on: April 22, 2014, 03:01:46 pm »
If you're using 2D physics, tile map box colliders don't have front or back faces.
If you're using 3D physics, you can add this if you want - its in the sprites poly collider cap settings, but....

In almost all cases its not necessary. If you use tile map.GetTileIdAtPosition( worldClickPos, layer ), you will know what tile you're clicking on. A tile id of -1 means no tile present, and anything else will be unique to the tile type. Its WAY more efficient to do this than add collider and faces...

mark

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Cannot Get Raycast to Hit Using Tilemap Mesh Collider
« Reply #2 on: April 22, 2014, 04:18:30 pm »
I'm trying to create a platformer, and trying to use the character controller at https://github.com/prime31/CharacterController2D 

When using the generated mesh collider on the tilemap, the player falls through the platform.  When I delete that mesh collider and manually add a box collider to the chunk, the player does not fall through. 

I think I have narrowed it down to raycast not hitting on the mesh colliders, but hitting on the box collider, but I don't know where to start on addressing that.  I don't think tilemap.GetTileIdAtPosition( worldClickPos, layer ) is the solution I'm looking for in this case.

I apologize, I'm new to Unity and tile maps, so I'm sure I'm missing something here.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Cannot Get Raycast to Hit Using Tilemap Mesh Collider
« Reply #3 on: April 23, 2014, 11:46:42 am »
Have you built your tile map with 2D physics? The character controller should work ok if your tile map has 2d physics.

mark

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Cannot Get Raycast to Hit Using Tilemap Mesh Collider
« Reply #4 on: April 23, 2014, 02:08:27 pm »
I can't find a way to build the tile map with 2D physics.  Is there a setting somewhere that I'm missing?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Cannot Get Raycast to Hit Using Tilemap Mesh Collider
« Reply #5 on: April 23, 2014, 02:15:49 pm »
Its in the sprite collection settings. You'll need to switch physics to 2D. Make sure the tile map has EdgeCollider2Ds instead of MeshColliders in the render data object.

http://2dtoolkit.com/docs/latest/unity_43_integration.html
« Last Edit: April 23, 2014, 02:23:03 pm by unikronsoftware »

mark

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Cannot Get Raycast to Hit Using Tilemap Mesh Collider
« Reply #6 on: April 23, 2014, 11:36:13 pm »
Sweet!  Working now.  Thank you very much.