I wanted to make a raycast to mouse, but as usual, I forget how to get the direction to the mouse, so i went to my usual bookmark of the guide making a laser gun, but it redirected me to a different guide that doesn’t show how to raycast to the mouse. So I went and looked it up to find another source, but the only thing i found was this:
local ray = Ray.new(point,((mouse - point).unit * 300))
Yet that produces weird results when close to an object as shown:
It saddens me such a good long guide that helped me so many times was replaced by something that doesn’t really help me too much.
Any help is appreciated.
I miss this tutorial so much, it was VERY helpful with understanding raycasts and the newer “tutorial” does not give me as much insight as the old tutorial did.
local ignorelist = {}
for i,v in pairs(char:GetDescendants())do
if v:IsA("MeshPart") then
table.insert(ignorelist,v)
elseif v:IsA("Part") then
table.insert(ignorelist,v)
end
end
for i,v in pairs(game.Workspace.Trash:GetChildren())do
table.insert(ignorelist,v)
end
for i,b in pairs(game.Players:GetPlayers())do
for i,v in pairs(b.Character:GetDescendants())do
if v.Parent:IsA("Tool") then
table.insert(ignorelist,v)
end
if v:IsA("Accessory")then
table.insert(ignorelist,v)
end
end
end
Heres the section of code that handles the ignorelist.
If I understand correct, you’re trying to cast a ray from the mouse’s origin to the mouse’s position in 3d space, you could use Mouse.Origin and mouse.Hit.P for that.
It used archaic practices- didn’t utilize remote events for example and that’s the reason it was updated, to employ better practice and teach it to newer developers.