Im working on a lazer weapon that will shoot a beam forward but will stop when it hits something cancollide true.
however because of the new raycasting system that was recently added, im having trouble using it.
right now if the lazer hits something cancollide false, instead of passing through it just doesnt fire at all.
if the lazer doesnt hit anything, it wont fire at all.
I want to be able to form the beam along the ray that was casted even if it doesnt hit anything while still ignoring cancollide false parts.
here is the code:
while true do
wait(4)
local origin = script.Parent.Position
local goal = script.Parent.CFrame.LookVector * 400
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
local visualbeam = Instance.new("Part")
visualbeam.CanCollide = false
visualbeam.Anchored = true
visualbeam.Size = Vector3.new(2,2,2)
visualbeam.BrickColor = BrickColor.new("Royal purple")
visualbeam.Material = Enum.Material.Neon
visualbeam.Name = "LazerBeam"
local filterlist = {}
for i = 1, 20 do
wait(0.1)
local part = workspace:Raycast(origin,goal,params)
if part and part.Instance:IsA("BasePart") and part.Instance.CanCollide == false then
params.FilterDescendantsInstances = filterlist
local v = (origin - part.Instance.Position)
visualbeam.CFrame = CFrame.new(part.Instance.Position + 0.5*v, origin)
visualbeam.Size = Vector3.new(part.Instance.Size.X, part.Instance.Size.Y,v.Magnitude)
elseif part and part.Instance:IsA("BasePart") and part.Instance.CanCollide == true then
visualbeam.Parent = game.Workspace
local v = (origin - part.Instance.Position)
visualbeam.CFrame = CFrame.new(part.Instance.Position + 0.5*v,origin)
visualbeam.Size = Vector3.new(visualbeam.Size.X, visualbeam.Size.Y,v.Magnitude)
end
end
if visualbeam then
visualbeam:Destroy()
end
end
could someone help walk me through this as the new raycasting system is new to me and doing things like ignore parts with certain properties have become a lot more complex.