Hello, I am trying to learn raycasting but I seem to be running into an issue
for some reason my raycast is getting nil if you look at the output (bottom left)
but then it randomly works at the same time?
Im currently trying to make a Beam but this issue is making it lag about
Aren’t like when you getting direction you must normalize it before using?
local Distance = 1000 -- How far ray will go.
local Direction = (mouse.Hit.p - origin.Position).Unit -- We getting here direction and property Unit returns normalized vector.
local ray = workspace:Raycast(origin.Position, Direction * Distance, params)
Use mouse.Move instead so you don’t need a loop. You should still keep the hold variable working though, as there’s no easy way to tell if the mouse buttons are being held down, without a variable and connections like this.
mouse.Move:Connect(function()
if hold then
-- code
end
end)
I also don’t know why you need to raycast? You can just set the beam start and end if mouse.Hit exists.
its works!, I decided to rewrite the script and not use raycast and it works very smoothly.
honestly a very simple script dont know why i overcomplicated it so much lol. thanks.