Im making a first person game, and im making the raycast origin the players head, and i need a raycast for every degree in the fov (70 degrees by default/raycasts) so how would i do that?
I thought of some option but im not confident about them, maybe there’s a better way?
for i = -35, 35 do
local direction = ???? (Thinking of the heads LookVector * distance of the ray, but how would i rotate the direction)
local raycastResult = workspace:Raycast(head.Position, direction, raycastParams)
if raycastResult then
print("Raycast hit!")
end
end
I don’t know how to rotate it tho, i know i could do Head.CFrame * CFrame.Angles(0, math.rad(i), 0) but that returns as a CFrame not a vector and i wouldnt know where to put it in the direction variable, any help would be appreciated, btw here’s a sketch
Welp im using a mesh so i guess i can’t do this, also thought about the cone approach but i’ll use it as my last option if i have to ill try the Camera:WorldToScreenPoint tho
If i did the Camera:WorldtoScreenPoint it would be on the client and i would have to fire a lot of remote events to see if the player sees the object or not, which is exploitable, any way to fix that?
It would be a good approximation still, and you could use one or two parts as the “visibility checker” proxy parts that were welded to the angle and invisible. You could also get the list of vertices of the mesh and use those in the script, but that’s more work.
One way or another you’re trusting the client. Like you could create a dummy camera on the server that you put at the same CFrame as a client’s and call the method on the dummy camera instead… but then how do you know the client isn’t sending you bogus camera CFrames? Ultimately roblox trusts the client implicitly because they handle their own physics. Not much you can do.