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:
I managed to get it working, but I’m not sure that this is a very good way to do it.
I changed the Collision_Default gameobject’s tag to a new Layer “Collision” for the tiled layers I want to have collision.
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;