Rough time trying to detect collisions
I'm working on basic procedural-made maps. For this I have a single "room" prefab in a starting position and then, using the Random Walk algorithm, other rooms are instantiated.
My problem comes when I'm trying to avoid that a room gets created on top of another one.
My idea is the following: I calculate the position in which the would-be room will be created and before creating it, I launch a OverlappingCircle in that position.
If I get at least one collision, then there's already a room there. I choose another direction and continue.
If no collisions, then I create the room
The problem is that this line, is always giving me Null
:
Collider2D roomDetection = Physics2D.OverlapCircle(newPosition, bigBigRadius, roomMask);
My prefab is a square, 10 units squared, with inner prefabs only on the edges, nothing is on the inside. Each one of this inner prefabs has a BoxCollider2D
. I even added BoxCollider2D
to the room prefab thinking it was somehing related, but I can't get the collision.
Thank you for any insight.
Answer by Larry-Dietz · Dec 13, 2019 at 10:13 PM
First thing I would try, is eliminate the mask, and see if you see the colliders then. If so, double check your layers and layer mask.
-Larry
Your answer
Follow this Question
Related Questions
Tilemap Collider problems 0 Answers
Collision between two 2D objects. 1 Answer
Car "bugs" through ground 0 Answers
Problems with raycasting 2D. Probelmas com raycasting 2D. 0 Answers
Destroying a projectile on collision 1 Answer