Disable camera peeking

Hello!
I would like to show you how to disable looking through transparent parts.
This is used in Jailbreak for example.

This is a very simple tutorial, but it may be very nice to some of you!

First of all, let’s show you what we are achieving.
We want to go from:

To:

So let’s get started!

To begin, you will need to get the PlayerModule, which can be found in game.StarterPlayer.StarterPlayerScripts
image

We are then going to copy this script while in playing mode (F5), and paste it in building mode (not playing) in the same location as you found it.

If you do not have anything in StarterPlayer, it should look like this:
image

Go into the child called CameraModule. Then look for ZoomController, and inside that a ModuleScript called Popper.

Scroll down to line 128, which should contain this chunk of script:

local function canOcclude(part)
	-- Occluders must be:
	-- 1. Opaque
	-- 2. Interactable
	-- 3. Not in the same assembly as the subject

	return
		getTotalTransparency(part) < 0.25 and
		part.CanCollide and
		subjectRoot ~= (part:GetRootPart() or part) and
		not part:IsA("TrussPart")
end

To disable looking through semitransparent parts, replace that part of the script with this:

local function canOcclude(part)
	-- Occluders must be:
	-- 1. Opaque
	-- 2. Interactable
	-- 3. Not in the same assembly as the subject

	return
		getTotalTransparency(part) < 1 and
		part.CanCollide and
		subjectRoot ~= (part:GetRootPart() or part) and
		not part:IsA("TrussPart")
end

You may be wondering what changed, so allow me to explain!
The line getTotalTransparency(part) < 1 and was first getTotalTransparency(part) < 0.25 and. Which made sure the camera would not go through parts with a transparency of less than 0.25

Now that we changed that number to 1, anything with a transparency below 1 (0 - 0.99…) will NOT allow the camera through. Parts with a transparency of 1 (or entirely invisible parts) will still allow this.

Now that you know how this is done, try it out for yourself!

Have fun developing,
SwissGermanGuy

19 Likes