Custom camera occlusion


I have a problem with this, I want the camera to stop before it hits a wall like this

So it would stop around here.

--Get service needed for events used in this script
local RunService = game:GetService("RunService")	

-- Variables for the camera and player
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
-- Constant variable used to set the camera’s offset from the player
local CAMERA_OFFSET = player.Character:WaitForChild("CameraOffset").Value
print(CAMERA_OFFSET)
camera.CameraType = Enum.CameraType.Scriptable

local function onRenderStep()
	-- Check the player's character has spawned
	if player.Character then
		if camera.CameraType == Enum.CameraType.Scriptable then
		local CAMERA_OFFSET = player.Character:WaitForChild("CameraOffset").Value
		local playerPosition = player.Character.HumanoidRootPart.Position
		local cameraPosition = playerPosition + CAMERA_OFFSET

		-- make the camera follow the player
			camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition)
		end
	end
end
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, onRenderStep)

This is the script I am using for the camera.

I personally used Ray Casts to solve this, I found an article as I can’t think of how to do this off the top of my head.

you should just be able to take the code from some of what 0_1195 said and put that in where – make the camera follow the player is.

1 Like