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

How would i limit a rays lenght? (solved)

Asked by 3 years ago
Edited 3 years ago

nvm all you needed to do was add ".Unit" before multiplying it

i made a raycasting script for a gun but i would like it to have limited range

heres my script

local gun = script.Parent
local event = gun.Shoot

local function OnEventFired(plr,mousePos)
    local shotOrigin = gun.Flare.Position
    local shotEnd = mousePos

    local shotDirection = (shotEnd - shotOrigin)*100

    local shotParams = RaycastParams.new()
    shotParams.FilterDescendantsInstances = {gun.Handle, gun.Flare}
    shotParams.FilterType = Enum.RaycastFilterType.Blacklist

    local shotResult = workspace:Raycast(shotOrigin,shotDirection)

    if shotResult then
        print(shotResult.Instance)
    end
end

i tried multiplying the rayDirection, but it just adds to the length, any help is appreciated :)

Answer this question