Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a physical lazer that goes straight using raycasting?

Asked by 5 years ago

Hello, im new to raycasting and im trying to make a lazer that goes straight and shoots every 7 seconds

So i have this raycasting script from a wiki post [https://www.robloxdev.com/articles/Making-a-ray-casting-laser-gun-in-Roblox] but mouse position and toolHandle are not defined since i want the ray to go straight. Any ideas?

local Lazer = script.Parent

local ray = Ray.new(Lazer.CFrame.p, (mouse.Hit.p - toolHandle.CFrame.p).unit * 300)
local beam = Instance.new("Part", workspace)
local distance = (Lazer.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(Lazer.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
0
replace toolHandle.CFrame.p with a Part's Position and replace mouse.Hit.p with the Part's Position + Part.CFrame.LookVector and whala Vulkarin 581 — 5y
0
The parent argument to Instance.new is deprecated, do not use it. and CFrame.p is deprecated use CFrame.Position. But do listen to Vulkarin. User#19524 175 — 5y

Answer this question