SuperTiled2Unity Prefab not colliding with collisions

Hello,
I am trying to get map collision working for a prefab but I can’t seem to get it working. I’ve tried adding Colliders to the root of the map gameobject, and also tried to do it for a specifc layer but I cannot get it working. I must be doing something wrong. If anyone could help it would be much appreciated. My skeleton project is here:

To move the warrior is WASD keys.

I managed to get it working, but I’m not sure that this is a very good way to do it.

  1. I changed the Collision_Default gameobject’s tag to a new Layer “Collision” for the tiled layers I want to have collision.
  2. I do a check in the Player objects script to see if the “Collision” Layer is behind it and only update the transformation if it’s not within the collision bounds.
        bool hit = Physics2D.Raycast(destination, -Vector2.up, 1, 1 << LayerMask.NameToLayer("Collision"));

        if (!hit)
            myRigidBody.transform.position = destination;

I got it working. I had to add some movement script and change the collision_default layers to collision.

Anyway I created a branch example in case anyone wants to re-use the code here:

1 Like