- Home /
The question is answered, right answer was accepted
Is it possible to make 2 raycast's collide with eachother?
Basically i'm doing my own custom procedural dungeon generation I have the rooms being generated correctly but now I need to create hallways that will link the rooms together and the way I thought of doing it is as diagrammed below.
I don't think you need raycasts. Just create lines and get the 2 lines crossing point: https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
Agreed, ray casting seems way over the top for this kind of thing.
You are generating them as if they were square rooms?, If not, you could have a big trouble trying to match the spaces between them if the hallways are not the right size, and no, you can make two raycast hit at intersection points, normally you check the Bounding Box for the volume distribution or implement some grid generation, cheers.
Answer by Sergio7888 · Sep 22, 2016 at 04:34 PM
Rayscast only hit Colliders, you need your room generator script use the room position to calculate the intersection point.
Example:
Vector2 roomA; //set with Room A position
Vector2 roomB; //set with Room B position
Vector2 IntersectionA=new Vector2(roomA.x, roomB.y);
Vector2 IntersectionB=new Vector2(roomB.x, roomA.y);
$$anonymous$$ore generally, they'd need to construct lines from the door positions (in whatever directions) then use a line intersection algorithm (see iabuko's comment) to find the corner points.
The bounding box is not necessary as the gameobject's transform is the origin of the room so simply drawing from that point that is already stored will be the best solution along with some basic Area and Pythag math to solve for the length and width from the room.
That will work although that diagram is just a sky view the actual game it is included in is 3d not a problem though I know how to convert it thanks :)
Follow this Question
Related Questions
How to render a lot of the same small objects 2 Answers
Create Vision Cone for Torch Effect Using Mesh 0 Answers
How can I create a 3d mesh using raycasts? 0 Answers
Raycast not working on terrain 0 Answers