workspace:Raycast(rayOrigin, rayDirection, RaycastParams)
The ray origin would simply be the point where the ray will start at, in your case you put the ray to start from the player’s humanoidrootpart.
The ray direction is the extent that your ray will detect things, so in your case, the part of the ray that you want to check at is the extent from the humanoid root part to the 0,100,0 vector.
By last there are the parameters for the ray, which I suppose you already know.
The reason of using Vector3 is because well, the Vector3 is a 3D point that involves position and direction (you can also search for Vector3 tutorials explaining about it on YouTube, which is not limited to roblox) meanwhile the other 3D point thing here is CFrame but we wouldnt need that since rays goes from a point to other so it doesnt need the rotation of a part (well, when you rotate a part the center will remain on the same point so it wont make any difference).
So well, if they used CFrame then it wouldnt make any difference than using Vector3 since the part center will remain on the same place even if you rotate it many times.
So to understand the direction you can use this, the blue vector “(end - start) if placed at origin” is the result of (endVector - startVector) but in the case of raycasting we use the rayOrigin, so the origin which normally is at 0,0,0 becomes the rayOrigin so with all this…
The ray becomes the (end - start) at the top between these 2 black vectors, since it simply moves the origin of the vector thats the result of (endVector - startVector) to the rayOrigin.
Now if you used (start - end), it would return the direction from the end to the start, and to simply explain this we can do the math now:
start = 0,6,6
end = 2,3,7
end - start = 2, -3, 1
Now lets put the origin at the start vector
0,6,6 + 2, -3, 1 = 2,3,7
It resulted on the end vector, so if the origin is 0,6,6 and the direction is the end vector - start vector then it will go from 0,6,6 till 2,3,7.
By the way, you are going to see this being used with Unit so many times, and if you wonder why they use it then there we go:
Unit returns a vector with the same direction but magnitude 1 (if you want the formula, its just each component divided by the magnitude of the vector) and the reason people uses it is because it remains the same direction and magnitude 1 so you can multiply it in order to give a “maximum distance”.
So in our case, if the rayDirection was (end - start).Unit*30 then the ray would start at the rayOrigin and face the direction from the rayOrigin to the rayDirection and would go to this direction by 30 units.
Maybe it wasnt good enough to understand so here is an example, lets say if you want to make a part that detects a player thats passing by its front and is in a distance of 10 units, for this we would do that:
--ill skip some parts and go straight to the ray
local start = part.Position
local direction = part.CFrame.LookVector -- This is a unit vector that starts from the part position and got the direction to where it is looking at, however as said before, the magnitude is 1 so its length is 1 and thats better for manipulation.
local rayResults = workspace:Raycast( start, direction*10, raycastParams)
-- By multiplying the unit vector by 10 you make its magnitude be 10 so it will detect whatever is in the front of the part at a distance of 10 units.
local humanoid = rayResults and rayResults.Instance and rayResults.Instance.Parent:FindFirstChild("Humanoid")
if humanoid then
print(" Someone was detected! ")
end
And for the last, explaining the way you used.
That way is actually pretty straightforward to explain so it wouls basically work the same way as the one I showed before, so it would go from the start point to the end point, the reason why I showed it in different places is because the first one is pretty important to understand the Unit way.
I guess this is all then, I hope I helped.