So I made a raycast for a weather system to detect if there’s shelter(by detecting if there’s something in the way) but since the part I used is too big and detects other stuff, I used a smaller part.
But for some unknown reason, that smaller part has the same issue?
Its detecting stuff from miles away even though its only meant to raycast to my head.
Yes it’s a really messy script
local rs = game:GetService("ReplicatedStorage")
local runservice = game:GetService("RunService")
local particle = rs:WaitForChild("Particle")
local clone = particle:Clone()
local clone2 = rs:WaitForChild("Origin"):Clone()
clone2.Parent = workspace
clone.Parent = workspace
local char = script.Parent
local head = char:WaitForChild("Head")
clone.Position = head.Position
local function isObstructed(PointA_Position, PointB_Position)
local Direction = (PointB_Position - PointA_Position) -- gives us our direction towards PointB_Position
local Raycast = Ray.new(PointA_Position, PointB_Position) -- Multiplier, just in case.
local Hit = workspace:FindPartOnRay(Raycast)
--workspace:FindPartOnRay() also has three more parameters you can pass through, respectively: what the Ray should ignore, whether the Terrain cells are cubes, and whether the ray should ignore the Enum.Material.Water.
if Hit then
return Hit -- If there was anything that got hit by the Raycast variable, return true.
else
return false -- If there wasn't anything in the way, return false.
end
end
runservice.RenderStepped:Connect(function()
clone2.Position = head.Position + Vector3.new(0,clone.Size.Y * 5,0)
clone.Position = head.Position + Vector3.new(0,clone.Size.Y * 5,0)
clone.ParticleEmitter.Texture = rs.Texture.Value
clone.ParticleEmitter.Speed = NumberRange.new(rs.Speed.Value)
if isObstructed(clone2.Position, head.Position) then
print(isObstructed(clone2.Position, head.Position))
clone.ParticleEmitter.Enabled = false
else
clone.ParticleEmitter.Enabled = true
end
end)