How to detect if a object is in the player's vision?

I know that WorldToScreenPoint exists, but it still returns true when the player doesn’t see the object but is facing the object (player is behind a wall but facing the object), How would i fix this/what alternative can i use?

You can try raycasting from the player head to the object, put the object on the whitelist and check if the raycast hit it.

Nice idea but wouldn’t raycasting from the camera be a better idea?

Is it 3rd or 1st person? On 1st person it wouldn’t matter much. It depends on how you perceive “player vision” in your game.

It’s a 3rd person game, but 1st person can also be used since the game uses the same roblox camera system. And by player vision i mean if the object can be seen anywhere in the player’s camera.

Raycasting from a camera should be possible using it’s CFrame.

there is a function local Pos, InScreen = Camera:WorldToScreenPoint(Vector3) The Pos variable is what position on the screen the Vector3 is, InScreen is a boolean saying if said position is on screen. Keep in mind the function doesn’t raycast, so if you had a part inbetween the camera and given point, the function would still return true for InScreen

I know about that, and what you said was what i said in the post.

Is raycasting not an option? It’s the best solution in my opinion

I’m currently trying it out, just having some errors.

You can get the angle of the part relative to the camera and check if it’s within the FOV of the camera, if it is, raycast from the camera to the part and if it intersects with the part then it’s within vision and nothing obstructs it.

local _, inScreen = Camera:WorldToScreenPoint(Part.Position)
 if inScreen then
 print("yes") -- or whatever you want it to do
end

Haven’t tested this but you can try.
This won’t print true and stuff. It SHOULD work even though you don’t want to use WorldToScreenPoint.

I’ve already found a fix to this, but the post said:

Well, as I said, I haven’t tested it.