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

RayCast against the sky?

Asked by
Kryddan 261 Moderation Voter
8 years ago

I am experimenting with raycasting guns but I am currently stuck. Whenever I try to shot at the sky nothing happens, is there something special with raycasting I have to do?

Here is everything that has to do with raycasting,

    local ray = Ray.new(
            handle.CFrame.p, --origin
           (((mouse.Hit.p - handle.CFrame.p).unit * 300) + (Vector3.new(math.random(-spreadX, spreadX),math.random(-spreadY, spreadY), 0))) --direction
        )
        local hit, position = workspace:FindPartOnRay(ray, character)

        clip.Value = clip.Value - 1

if not hit then
    return false    
end
------------------
local distance = (handle.CFrame.p - position).magnitude
bullet.Size = Vector3.new(0.2,0.2,distance)
bullet.CFrame = CFrame.new(handle.CFrame.p,position) * CFrame.new(0,0, -distance / 2)

1 answer

Log in to vote
0
Answered by 8 years ago

You're returning if you hit nothing. If you shoot the sky, you hit nothing.

0
That seems logical but it doesn't work Kryddan 261 — 8y
0
Well, it does work because that's exactly what you're doing dude. User#6546 35 — 8y
Ad

Answer this question