Didn’t find a post with a valid solution, so here:
function RoundHandler.RegisterShot()
local viewPort = camera.ViewportSize / 2
local origin = camera.CFrame.Position
local direction = (camera.CFrame * CFrame.new(Vector3.new(viewPort.X, viewPort.Y, 0))).LookVector
local params = RaycastParams.new()
params.FilterDescendantsInstances = {Players.LocalPlayer.Character}
params.FilterType = Enum.RaycastFilterType.Blacklist
local result = workspace:Raycast(origin, direction, params)
print(result)
end
For some reason it is nil, don’t comprehend why. Raycast documents are too confusing for me.
if the :RayCast(...) returns nil, it means that it hasn’t intersected with anything thus returning nil.
Maybe check if you’re sending the ray in right direction or it is long enough.
Maybe try visualizing the raycast to see how long it is or which direction it aims.
EDIT:
The direction variable seems to be too short, you’re only getting the .LookVector (look vectors have length of 1 stud), maybe try multiplying the whole direction with some magic number.
Oh, what number are you multiplying it with. It can be a littly tricky since the camera position could be x studs away from the instance, so either try doing some math or send the raycast on a really long trip