RaycastResult becomes nil when ray doesnt hit anything

So I’ve been using this new RaycastParams thing for my guns and things are fine until I shoot in the air.

Normally, when you make a ray and the ray doesn’t hit anything, it returns a Vector3 of where the ray ended and you can work with that, but when I use RaycastResult.Position it returns nil. So the question is, what do I use now? Is there a way to get the endpoint of the ray or do I have to switch to the old Ray.new() method?

2 Likes

Logically, if the ray didn’t hit anything, the “hit position” is origin + direction.

5 Likes

You are correct, but I’ve just found the actual problem (im a bruh moment)

Turns out WorldRoot:Raycast() returns nil if the ray doesn’t hit anything. Yikes. I’ve found a method to fix this. Thanks for helping!

1 Like

Yeah i was going to point out that WorldRoot:Raycast actually returns nil instead of just an empty raycast params, but you got it

1 Like

Hey Im having this issue too, but I dont know how to add the start position with the direction because I want the end position of the ray but like Direction*300 kind of end… so how do I get that position?

1 Like

I did solve my own issue! just in case anyone has another issue with this:

local Direction = To - Origin
local Vector = Origin + Direction * 10
--this gives you the end vector of the Start point and the Direction
--To is supposed to be my target direction ( It was my mouse in this case )
--Origin is just the Start Point
8 Likes