I am making a movement system, basically I am trying to detect the part in front, right and left of the character with ray cast. I manage to detect the part in front with lookvector but I have no idea how to do the sides (left, right) here is my script
local MainPart = script.Parent
while wait(0.5) do
local FrontRay = Ray.new(MainPart.Position, MainPart.CFrame.LookVector * 50)
local Fronthit = workspace:FindPartOnRayWithIgnoreList(FrontRay, {MainPart})
if Fronthit then
local distance = (MainPart.Position - Fronthit.Position).Magnitude
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Material = "Neon"
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.lookAt(MainPart.Position, Fronthit.Position)*CFrame.new(0, 0, -distance/2)
p.Parent = game.Workspace
print(Fronthit.Name)
wait(0.2)
p:Destroy()
else
print("no")
end
end