Create new rays, based on forward but rotated

I’m creating an A* pathfinding algorithm and I’m trying to draw 4 rays in all directions:

  • One which will be pointing forward
  • One to the back
  • One to the left
  • One to the right

To draw the forward ray, I simple used:

    forwardRay.origin = transform.position;
    forwardRay.direction = transform.forward;

Works perfectly, but how do I add a side ray? It must be added to the forwardray, but I’m stuck with what kind of rotation method I have to add.

You can do this:

backRay.origin = transform.position;
backRay.direction = -transform.forward;

rightRay.origin = transform.position;
rightRay.direction = transform.right;

leftRay.origin = transform.position;
leftRay.direction = -transform.right;