I’m trying to make it so that the player’s character is visible while in first person, but since the camera is offset, the camera clips into walls whenever a player walks up to one:
I’m trying to make it look something like this instead:
I’ve tried to fix this by using a Spherecast and CFraming the player back if the cast touches the wall. It sort of worked, but is very glitchy. Is there any way I can manage to achieve this?
Here is the code I used for this. It’s kinda sloppy, but it works for testing purposes:
local Character = script.Parent
for i, v in pairs(Character:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Head" then
v.Changed:Connect(function()
v.LocalTransparencyModifier = 0
end)
end
end
Character.Humanoid.CameraOffset = Vector3.new(0,0, -1)
local rp = RaycastParams.new()
rp.FilterType = Enum.RaycastFilterType.Exclude
rp.FilterDescendantsInstances = {Character}
game:GetService('RunService').RenderStepped:Connect(function()
local castResult = workspace:Spherecast(Character.Head.Position, .5, Character.Head.CFrame.LookVector, rp)
if castResult then
Character.PrimaryPart:PivotTo(CFrame.new(Character.HumanoidRootPart.Position + (Character.HumanoidRootPart.CFrame.LookVector).Unit * (castResult.Distance - .45)))
end
end)