Good morning.
I want to shoot rays at random points on the horizon. This way the NPC will pick an empty space.
But even with this minimal script I had problems. The rays never hit anything.
local function getRandomPointInCircle(centerPosition)
local rayOrigin = centerPosition
local RANDOM_DEGREES = math.random(0, 360)
local rayDirection = CFrame.Angles(math.rad(90), math.rad(RANDOM_DEGREES), math.rad(0)).lookVector
local ray = Ray.new(rayOrigin, rayDirection)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
print(raycastResult)
end
for i = 1, 100 do
getRandomPointInCircle(Vector3.new(0, 5, 0))
task.wait(0.1)
end
I tried to visualize the rays with parts, but they all have magnitude 1. I’ve also tried to shoot rays in every direction, but they still don’t hit anything.
Any help would be appreciated!