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

How does the max distance work with ray casting? *SOLVED*

Asked by 6 years ago
Edited 6 years ago

I made a gun that uses ray casting from watching a few videos I found online. The last argument to the ray is its max distance however, no matter what value I plug into this the bullet travels to wherever I clicked and doesn't stop before it. Can anyone explain to me how the max distance works? For reference, here's the script that I'm talking about:

--serverscriptservice

local remote = game.ReplicatedStorage:WaitForChild("events"):WaitForChild("shotgunShoot")

remote.OnServerEvent:connect(function(player, barrelPos, mousePos)
    local ray = Ray.new(barrelPos, (barrelPos - mousePos).unit * 100) --start, travel from, max distance
    local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false, true)
    --cant hit themself, false is smooth terrain, true ignores water

    local distance = (barrelPos - mousePos).magnitude
    remote:FireAllClients(player, part, position, distance, barrelPos)



end)
0
I got it we're all good sonicfan0405 18 — 6y

Answer this question