I was wonder how do you make a ray-casting object detect all angles of it like a sensor. It keeps going in one direction forward and I want it to be 360 like around all of the part.
while true do
wait()
local Raycast = Ray.new(script.Parent.CFrame.p, script.Parent.CFrame.LookVector * 500, script.Parent.CFrame.UpVector * 500, script.Parent.CFrame.RightVector * 500)
local Part, Position = game.Workspace:FindPartOnRayWithIgnoreList(Raycast, {script.Parent}, false, true)
print(Part)
end
Yeah well, I don’t know what your point is for a 360 degrees raycasting detection, but it won’t still work
you will need thousands of raycasts depending on the distance.
So 360 isn’t enough.
example of what would happen:
But if you really wanna go for it.
I mean… sure?
local part = workspace.Sensor
local angle = 0;
local params = RaycastParams.new()
params.FilterDescendantsInstances = {part}
for i = 1,360,1 do
angle = i;
local startCFrame = part.CFrame * CFrame.Angles(0,math.rad(angle),0)
local Raycast = workspace:Raycast(part.Position,startCFrame.LookVector.Unit * 200,params)
if (Raycast) then
-- stuff here
print("detected",Raycast.Instance)
end
end
If you want 360-like spherical 360, then a raycast would not be accurate or effective, try:
local sensor = workspace:WaitForChild("Sensor")
local sensed_parts = {}
for _, v in pairs(workspace:GetChildren()) do
if v:IsA("BasePart") then
if (v.Position - sensor.Position).Magnitude <= 200 --[[ this is the radius of studs the sensor will detect in, make this a constant variable --]] then
table.insert(sensed_parts, v)
end
elseif v:IsA("Model") then
if v.PrimaryPart then
if (v.Position - sensor.Position).Magnitude <= 200 --[[ this is the radius of studs the sensor will detect in, make this a constant variable --]] then
table.insert(sensed_parts, v)
end
end
end
end
print(sensed_parts)
or:
if (v.Position - sensor.Position).Magnitude <= 200 then
sensed_parts[v] = true
else
sensed_parts[v] = false
end