1
\$\begingroup\$

I am relatively new to game development, and am working on a simple 2D platformer. I have created a tilemap and painted some tiles for the character to walk on.. but he is getting stuck. Yes, I know this is a common question and I did find some answers (including this one: Player gets stuck on edges between TilemapCollider2D tiles), but none seem relevant for me. The thing is my tiles are not flat.. they have pointy edges due to grass.. see the image below:

Grass tile with jagged collision edge

As you can see, the edge is not flat. I have overcome the problem of getting stuck by changing the "Edge Radius" to what you see in the above screenshot and that works, but the character now looks like he is floating slightly above the ground. Is there any way I can just tell Unity to ignore the jagged grass and make the collider flat and move the edge of it down a bit? That way it would fix the issue and also have the added bonus of looking like some of the grass is behind him and some in front..

\$\endgroup\$
1

2 Answers 2

2
\$\begingroup\$

Thanks to @DMGregory, the solution for anyone else with the same question is as follows:

  • Find the sprite in your project
  • Open the sprite editor from the inspector
  • Edit the collider

If you don't set any collider here, it appears Unity will figure it out for you instead.. which in my case was not appropriate. I just made my collider into a box.. as follows:

enter image description here

and so my Scene view now appears as follows:

enter image description here

Additionally, I removed the Rigidbody 2D and the Composite Collider 2D and unchecked the Used by Composite checkbox in the Tilemap Collider 2D.

It now works great.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ You will probably still want the composite collider here, as it can also help with efficiency by combining large groups of colliders, and avoid snags at the seams between tiles. \$\endgroup\$
    – DMGregory
    Commented May 15, 2020 at 13:25
  • \$\begingroup\$ Thanks for that info. I've added the composite collider back and I see what you mean. \$\endgroup\$
    – Matt
    Commented May 15, 2020 at 13:41
  • \$\begingroup\$ Great work solving the problem! I'm looking forward to seeing your game develop. :) \$\endgroup\$
    – DMGregory
    Commented May 15, 2020 at 14:06
  • \$\begingroup\$ I am having a very similar issue. I want to be able to make the tilemap collider flat and not the shape of the tiles. I tried what you suggested by editing the sprites and that gives me the offset that I needed but not a flat collider, it is still the shape of the sprite. The problem with the tilemap collider being the shape of the sprite is that the character/player moves/follows ever imperfection, so a flat surface would allow the character to move smoothly across the platform. \$\endgroup\$ Commented Jan 22, 2021 at 1:08
  • \$\begingroup\$ @Matt the particular screenshot used here might be misleading. Want to snap one where you're using the Custom Physics Shape mode of the sprite editor? It looks like another user got the impression that all you need to edit are the Border settings shown in this screenshot, which are used for 9-slice scaling, not collision. \$\endgroup\$
    – DMGregory
    Commented Jan 22, 2021 at 18:36
0
\$\begingroup\$

I was having a similar issue as above. DMGregory pointed out that using the custom Physics Shape and also may need to switch the Tile to Grid collision and back to Sprite again for it to load the updated collision shape.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .