I am trying to fire raycasts out at different angles and only one the Left one is working
this is what I mean:
when it should look like:
I have tried to figure this out but I can’t
here is my code:
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Part = Instance.new("Part")
Part.Color = Color3.fromRGB(255, 0, 0)
Part.Transparency = 0
Part.Size = Vector3.new(.1, .1, 0)
Part.Anchored = true
Part.CanCollide = false
local RaycastDrawnLines = {
Left = Part:Clone(),
LeftDiagonal = Part:Clone(),
Front = Part:Clone(),
RightDiagonal = Part:Clone(),
Right = Part:Clone()
}
table.foreach(RaycastDrawnLines, function(_, Value)
Value.Parent = workspace
end)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {
Character
}
local UpdateRaycastLine = function(Name, Raycast)
RaycastDrawnLines[Name].Size = Vector3.new(.1, .1, Raycast.Distance)
RaycastDrawnLines[Name].CFrame = CFrame.new(HumanoidRootPart.Position:Lerp(Raycast.Position, .5), Raycast.Position)
end
local Update = function(Length)
local origin = HumanoidRootPart.Position
local direction = -HumanoidRootPart.CFrame.RightVector * Length
local Left = workspace:Raycast(origin, direction, raycastParams)
local direction2 = (-HumanoidRootPart.CFrame.RightVector + HumanoidRootPart.CFrame.LookVector) * Length
local LeftDiagonal = workspace:Raycast(origin, direction2, raycastParams)
local direction3 = HumanoidRootPart.CFrame.LookVector * Length
local Front = workspace:Raycast(origin, direction3, raycastParams)
local direction4 = (HumanoidRootPart.CFrame.RightVector + HumanoidRootPart.CFrame.LookVector) * Length
local RightDiagonal = workspace:Raycast(origin, direction4, raycastParams)
local direction5 = HumanoidRootPart.CFrame.RightVector * Length
local Right = workspace:Raycast(origin, direction5, raycastParams)
if Left then
UpdateRaycastLine("Left", Left)
elseif not Left then
RaycastDrawnLines.Left.Position = Vector3.new(0, workspace.FallenPartsDestroyHeight, 0)
elseif LeftDiagonal then
UpdateRaycastLine("LeftDiagonal", LeftDiagonal)
elseif not LeftDiagonal then
RaycastDrawnLines.LeftDiagonal.Position = Vector3.new(0, workspace.FallenPartsDestroyHeight, 0)
elseif Front then
UpdateRaycastLine("Front", Front)
elseif not Front then
RaycastDrawnLines.Front.Position = Vector3.new(0, workspace.FallenPartsDestroyHeight, 0)
elseif RightDiagonal then
UpdateRaycastLine("RightDiagonal", RightDiagonal)
elseif not RightDiagonal then
RaycastDrawnLines.RightDiagonal.Position = Vector3.new(0, workspace.FallenPartsDestroyHeight, 0)
elseif Right then
UpdateRaycastLine("Right", Right)
elseif not Right then
RaycastDrawnLines.Right.Position = Vector3.new(0, workspace.FallenPartsDestroyHeight, 0)
end
return {
Left = Left,
LeftDiagonal = LeftDiagonal,
Front = Front,
RightDiagonal = RightDiagonal,
Right = Right
}
end
while true do
Update(100)
task.wait()
end