1
\$\begingroup\$

How can we get one way collisions using Tilemaps in Unity?

There doesn't seem to be much online regarding this topic yet.

From this link: https://answers.unity.com/questions/1471156/how-to-make-one-way-platforms-using-a-tilemap.html, I got that we should use a Tilemap Collider 2D for collisions and not use a Composite Collider 2D. Finally, we need a Platform Effector 2D with One-Way enabled.

However, the resulting tiles all behave like normal tiles in that collisions occur along all edges.

Here's what the inspector looks like for the tile map in question. Inspector for the One Way Tilemap

The scene setup looks like this: enter image description here

It looks like the tiles in the scene all have collision edges all the way around.

What needs to be done to allow for one way platforms? Thanks!

EDIT

Here is the setup of the character:

enter image description here

Here is a view of what it looks like in game: When jumping, the character unfortunately collides with the block above and is unable to pass through.

enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ Just to confirm, have you actually run the game to test your effect? Could you also show the setup of your character/object that you say collides in every direction? There's nothing glaringly wrong with your tilemap setup. \$\endgroup\$ – andeart Jul 11 '18 at 23:28
  • \$\begingroup\$ @andeart thanks for the response! I have run the game to test the effect. I've updated the question to include the character's setup. Could it be one of the settings belonging to the Rigidbody2D or BoxCollider2D? \$\endgroup\$ – WayWay Jul 11 '18 at 23:52
  • 1
    \$\begingroup\$ Could you try (a quick change, for the sake of this problem) changing your character's RB settings to Dynamic? \$\endgroup\$ – andeart Jul 12 '18 at 0:11
  • 1
    \$\begingroup\$ @andeart thanks for the suggestion! I gave it a try and changed it to dynamic. However, I'm still not able to have the character jump through the platforms one way. The interaction between character and tiles is the same.. Do you have a minimal example that I could reference which demonstrates one-way collision tile maps? That would be incredibly helpful - thank you! \$\endgroup\$ – WayWay Jul 12 '18 at 0:45
  • 2
    \$\begingroup\$ I just set up a quick sandbox project. In an empty scene (make sure your code isn't in there to remove that doubt)- create a tilegrid in the scene, add a tile. Add the components setup from your screenshot. Create a Sprite,Rigidbody2d,BoxCollider2D,Dynamic setup on a new object. Place this object underneath the platform. Set its gravity scale to -1. Run the scene. Watch the object float up. After it crosses, while still in play mode, change the gravity back to 1. Confirm that the collider only goes one way and not the other. \$\endgroup\$ – andeart Jul 12 '18 at 0:49
1
\$\begingroup\$

The culprit turned out to be custom collision/physics code that OP had written separately (which I do not have access to).

We ran a few test cases. Confirmed that PlatformEffector2D does, in fact, work as expected on a TilemapCollider. No special steps needed to set it up.

\$\endgroup\$
  • \$\begingroup\$ I don't think this answers the question, as the question is about how to achieve the one way collisions in a tilemap. He knows that it is not a Unity problem, but he is just describing the way he tried attempting to solve the problem before asking here. This answer doesn't help and IMHO should be a comment and not an answer. \$\endgroup\$ – Sri Harsha Chilakapati Jul 12 '18 at 4:35
  • \$\begingroup\$ Please give a summary of your comments discussion in this answer. That will help the new users as not everyone will look at the comments section. \$\endgroup\$ – Sri Harsha Chilakapati Jul 12 '18 at 4:36
  • 1
    \$\begingroup\$ That's a good point. Updating my answer. \$\endgroup\$ – andeart Jul 12 '18 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.