Send raycasts in all directions

Hello there! I’m currently programming an AI that can drive the cars in our upcoming game. For this to fully work, I need to send raycasts in all directions around my car to be able to provide data for the AI.

Currently, I’ve figured out all the directions I need except for the BackLeft and BackRight.

My back raycast’s direction is done like this: -backRaycastPart.CFrame.LookVector * distance

My front raycasts’ directions are done like this: Front: raycastPart.CFrame.RightVector * distance
FrontLeft: Vector3.new(raycastPart.CFrame.RightVector.X, 0, raycastPart.CFrame.LookVector.Z) * distance
FrontRight: Vector3.new(raycastPart.CFrame.RightVector.X, 0, -raycastPart.CFrame.LookVector.Z) * distance

Any ideas on how I could do BackLeft and BackRight?

1 Like

Wouldn’t it be better to use pathfinding instead of sending raycasts in all directions?

1 Like

That’s not how it works… I’m programming a self driving car using neural networking, I need to send the raycasts to get the AI to have something to work with. I’m simply using the distance from the car to the raycast hit.

The pathfinding service cannot drive a car, as far as I know.

1 Like

Could you maybe post a picture labelled with all the vectors you have and are trying to find?

1 Like

Sure, give me a few minutes. I’ll have to start my computer.

1 Like

You can use pathfinding to drive the car. I have been able to program AI that could drive cars using pathfinding.

1 Like

Cool. Regardless, I’m gonna stick with training my own AI to do it.

1 Like

Here.


The ones with black text are the ones I want, I drew 2 red lines to show how they would be cast. The ones with white text are the ones I already have.

1 Like

BackLeft should be just be -FrontRight, and BackRight should just be -FrontLeft.

1 Like

Backleft will be:

Vector3.new(-raycastPart.CFrame.RightVector.X, 0, raycastPart.CFrame.LookVector.Z) * distance

and BackRight will be:

Vector3.new(-raycastPart.CFrame.RightVector.X, 0, -raycastPart.CFrame.LookVector.Z) * distance

Is this what you meant?

That sounds very logical. But dang it, I just got to school. I’ll try it out once I’m home. Thanks!