How to fix first person camera clipping? Solution

If you are having a problem with the camera clipping, here is the solution.

Well, I don’t have to explain here much.

Problem:

Fixed:

Solution:
Screenshot 2024-03-28 095047

Code (TS):
Screenshot 2024-03-28 095226

Code (Luau):

local head = --head of the character
local camera_offset = --offset from the centre of the head to the face

local head_collision_part = Instance.new("Part", head)
head_collision_part.Massless = true
head_collision_part.Transparency = 1
head_collision_part.Size = Vector3.one * .5
head_collision_part.Parent = head

local weld = Instance.new("Weld", head)
weld.Part0 = head
weld.Part1 = head_collision_part
weld.C0 = CFrame.new(camera_offset)
7 Likes

You are absolutely right. I made a change, hopefully, it’s more clear now

3 Likes

Hmm… This code isn’t particularly helpful. You should provide a Luau script that has everything setup already!

7 Likes

A fellow roblox-ts user, you have my respect :slight_smile:

2 Likes

A fellow roblox-ts use, you have mine as well :slightly_smiling_face:)

1 Like

it will not be much different, the code where it’s located is big.
This is used for a FirstPerson camera class, so unless you are making your camera script, it’s not going to be useful.
The camera in my case is located in the face instead of the head to get the proper body view.
The luau will look something like this.

local head = --head of the character
local camera_offset = --offset from the centre of the head to the face

local head_collision_part = Instance.new("Part", head)
head_collision_part.Massless = true
head_collision_part.Size = Vector3.one * .5
head_collision_part.Parent = head

local weld = Instance.new("Weld", head)
weld.Part0 = head
weld.Part1 = head_collision_part
weld.C0 = CFrame.new(camera_offset)
1 Like

Instead of creating a part, you can just add a script to always get the wall in front of the camera, after that you just need to get the distance and if it’s going past the front point of the head you offset the camera by the distance value.

You can do that using the camera’s LookVector to set a direction of a Ray and then you just need to get the magnitude between the Ray’s result and the Head/Camera.

You should do that for both Z and Y axis.

2 Likes

Your solution is very great for weapon collision with the wall and maybe fps. If you offset the camera to the face, you don’t need to check both axes. The face is on the -Z axis.
The solution with a cube is very simple I think, because you don’t have to ray cast and do additional checks, just create a cube and put it right into the camera. The goal is just to prevent the camera from going through the wall.

3 Likes

does this solution be able to let the character climb through trusses, ladders even there’s a part blocking?

2 Likes

to my surprise, it lets you climb the trusses and ladders

I didn’t test for the animations that position you very close to the ladder (no idea if they even exist)
But for 99% of cases, it will work normally because your character is positioned back from the ladder.
Can you tell me if you will find a problem with that, maybe I can help.
The implementation is very easy and is easily changeable, so it is worth nothing to try I think

1 Like