Problem with camera offset

I’m making a camera offset, and currently the camera can go through walls. How would I fix this?
code so far (doesn’t work well, is in a renderstepped):

local Cast = workspace:Raycast(HumanoidRootPart.Position,Humanoid.RootPart.CFrame.RightVector * 1.5,Params)
	if Cast then
		Humanoid.CameraOffset = Vector3.new((HumanoidRootPart.Position.X - Cast.Position.X),Humanoid.CameraOffset.Y,Humanoid.CameraOffset.Z)
		print(Cast.Distance)
	else
		Humanoid.CameraOffset = Vector3.new(1.5,Humanoid.CameraOffset.Y,Humanoid.CameraOffset.Z)
	end
1 Like

wrote it on my phone sorry:

local collidingPart = instance.new(“Part”, workspace.currentcamera)
collidingPart.Anchored = true
collidingPart.Size = vector3.new(1,1,1)

local Cast = workspace:Raycast(HumanoidRootPart.Position,Humanoid.RootPart.CFrame.RightVector * 1.5,Params)
if Cast then
Humanoid.CameraOffset = Vector3.new((HumanoidRootPart.Position.X - Cast.Position.X),Humanoid.CameraOffset.Y,Humanoid.CameraOffset.Z)
print(Cast.Distance)
collidingPart.CFrame = workspace.CurrentCamera.CFrame
else
Humanoid.CameraOffset = Vector3.new(1.5,Humanoid.CameraOffset.Y,Humanoid.CameraOffset.Z)
collidingPart.CFrame = workspace.CurrentCamera.CFrame
end

(Starter Character script)

Does that work or do you need to add the camera offset to it?

1 Like

When my camera is up againest the wall it through it

Image

try Z -= raycastresult.instance.size.Z in your offset?

(idk quick guess)