How to check if player's camera is inside some part?

Is there a way of checking if player’s camera is in a part?

2 Likes

You will have to get the Camera CFrame and get the Part Position and magnitude check the two.

2 Likes

You could pass the local camera’s CFrame position and the part into this function:

function isInsideBrick(position, brick)
	local v3 = brick.CFrame:PointToObjectSpace(position)
	local size = brick.Size / 2
	return (math.abs(v3.X) <= size.X)
		and (math.abs(v3.Y) <= size.Y)
		and (math.abs(v3.Z) <= size.Z)
end
8 Likes