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

Raycasting being strange? First time using raycasts

Asked by 7 years ago

To prevent people from shooting through walls by putting their weapons inside the wall and then firing, I was suggested the idea of using a raycast from the barrel to the head and in if a part is detected, the gun won't fire. This doesn't seem to be working for me when I put it in action - the raycast doesn't work as intended (not working on certain areas etc...).

    local firing = true
    local gunray = Ray.new(Gun.Barrel.Position, Head.Position)  

    local part, endpoint = workspace:FindPartOnRay(gunray, Character)
    if part then
        if part.Parent.name ~= Gun.Name then
            firing = false
        end
    end

All help is appreciated, thank you!

0
Have you tried starting the ray from the start of the players arm, or just before the start? User#5423 17 — 7y
0
local gunray = Ray.new(Character:FindFirstChild("Right Arm").CFrame.p, Gun.Main.CFrame.p) - Is this what you mean, as it still doesn't work and is finding parts that it shouldn't coolyoshipower 42 — 7y

Answer this question