How to tell if camera is in a part?

how would i go about telling if the players camera is inside a region3?? is that even possible?

or would i have to trace out the regions myself and tell myself like below?

local Cam_X = Camera.CFrame.Position.X;
local Cam_Y = Camera.CFrame.Position.Y;
local Cam_Z = Camera.CFrame.Position.Z;


local Liquid_X = Liquid.Position.X;
local Liquid_X_Size = Liquid.Size.X;
local Liquid_Y = Liquid.Position.Y;
local Liquid_Y_Size = Liquid.Size.Y;
local Liquid_Z = Liquid.Position.Z;
local Liquid_Z_Size = Liquid.Size.Z;

if Cam_X < Liquid_X + Liquid_X_Size / 2 and Cam_X > Liquid_X - Liquid_X_Size / 2 and Cam_Z < Liquid_Z + Liquid_Z_Size / 2 and Cam_Z > Liquid_Z - Liquid_Z_Size / 2  then
    local Raycast_Params = RaycastParams.new();
    Raycast_Params.FilterType = Enum.RaycastFilterType.Blacklist;
    Raycast_Params.FilterDescendantsInstances  = {Character, Liquid};
    local RayCast = workspace:Raycast(Vector3.new(Cam_X, Liquid_Y, Cam_Z), Vector3.new(0, -999, 0), Raycast_Params);
    if (RayCast) and Cam_Y < Liquid_Y + Liquid_Y_Size / 2 and Cam_Y > Liquid_Y - Liquid_Y_Size / 2 and (Humanoid.Health > 0) then
        --etc lol
    end
end

I appreciate all the responses, and thank you for taking the time to read this. :smile:

1 Like

Okay, well, I found a fix! (not completely finished, though)

for __, Liquid in pairs(workspace.Liquids:GetChildren()) do
			local Raycast_Params = RaycastParams.new();
			Raycast_Params.FilterType = Enum.RaycastFilterType.Blacklist;
			Raycast_Params.FilterDescendantsInstances  = {Character};
			local RayCast = workspace:Raycast(Camera.CFrame.Position, (Liquid.Position - Camera.CFrame.Position), Raycast_Params);
			
			if (RayCast) and (CameraLiquid == Liquid) then
				print("Not in water");
				CameraLiquid = nil;
				ColorCorrectionEffect.Enabled = false;

				Underwater_Ambience:Pause();
				DepthOfField_Effect.Enabled = false;
			elseif not(RayCast) then
				print("In water");
				CameraLiquid = Liquid;
				ColorCorrectionEffect.TintColor = CameraLiquid:FindFirstChild("Color").Value;
				ColorCorrectionEffect.Enabled = true;
				DepthOfField_Effect.Enabled = true;

				if (Underwater_Ambience.IsPlaying) then return; end
				Underwater_Ambience:Play();
			end

when two parts intersect, they don’t want to… render the camera?

I’m unsure about how to go on this, what should I do?

Figured it out, all I had to do was search around a little more, I found a forum post on how to get a point in a bounding region, these helped me as well!

1 Like