Ray search

Hello first time here.
Here’s my problem :
11874-example.png

I’m working on 2D
(X,Z) Y is constant at 60

I want to make sure that an intersection can “search” around for a Road (these are simple cubes)

These cubes have scripts attached to em (Road,Intersection)

So, in my script, I have this :

#Intersection#
//posXZ is a table that contains the coords of the intersection (X,Z)
vectu = new Vector3(posXZ[0]-2,60,posXZ[1]);
ray = new Ray(vectu,vectu - new Vector3(0,60,0));
RaycastHit hit ;
if (Physics.Raycast(ray,out hit))
{
//DO SOMETHING
}

My problem is that, i don’t know how to use properly the direction mentionned in the manual for RAY.
I know that i have to create a total of 4 rays which are gonna check in a range of 2 units if there’s a cube with the tag “road” but i don’t really know how to use the direction.

Can somebody explain with a little diagram please ?

I think, that Scripting Reference with description of Ray() constructor is very helpful. There is example:
public Ray ray = new Ray(transform.position, transform.forward);

In your case the solution could be (depending on how you have the coordinates setup):

  • rayUp = new Ray(transform.position,
    Vector3.up);
  • rayDown = new Ray(transform.position,
    Vector3.down);
  • rayLeft = new Ray(transform.position,
    Vector3.left);
  • rayRight = new
    Ray(transform.position,
    Vector3.right);

Yeah, haven’t seen these functions… :frowning:
It’s working anyway, thanks !