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)
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)
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.
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.
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