Hello,
I am currently coding a laser and it’s going pretty well, but when the laser is pointing in the sky, it doesn’t work correctly. What I mean:
And this is my code
local barrel = viewModel:FindFirstChild("Barrel",true)
local shootPart = barrel:FindFirstChild("Shoot")
local laserLight = laser:FindFirstChild("LaserLight")
local startAttachment = laserLight:FindFirstChild("Start")
local endAttachment = laserLight:FindFirstChild("End")
while wait() do
if not Modules.IsEquipped then break end
endAttachment.Visible = laserEnabled
if laserEnabled then
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character,viewModel}
raycastParams.IgnoreWater = true
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local direction = shootPart.CFrame.LookVector
local range = config.Range and config.Range or 100
local result = workspace:Raycast(shootPart.Position,direction*range,raycastParams)
if result and result.Position then
endAttachment.WorldPosition = result.Position
end
else
endAttachment.WorldPosition = startAttachment.WorldPosition
end
end
So how can I fix this? Thanks!