Okay, I don’t have your code, so I can’t do it for you. But I’ll explain this is easily as possible. Ofcourse, I’m assuming you made this yourself and can change it.
Step 1: What are the vectors for the camera changing? This would work best if it’s just offset like this: Vector3.new()
because it’s only 1 axis, which means it needs 1 raycast. If you have more than 1 axis changing, then you need multiple raycasts.
Step 2: Find the normal camera CFrame. Just set it as a variable in your loop so you have it for the next step.
Step 3: Raycast from that CFrame, to the direction you want the camera to be, and the length is how much you want the camera to go in that direction.
Step 4: Check if no raycast was hit, if the raycast hit nothing, then you can move the camera like you have been doing, and skip the next step.
if not raycast then
-- normal code you have
return -- so it doesnt continue past this if no raycast was hit
end
Step 5: If the raycast was hit, you need to check the distance from the origin of the raycast, to the point it hit, like this.
local distance = (Origin - Raycast.Position).Magnitude)
Step 6: Divide the distance of that we just got, by the distance of the entire raycast. So if the raycast was 5 studs long, it would look like this:
local percentage = distance / 5
Step 7: Multiply the offset of the camera for the axis we just raycasted for, by that percentage. So if it was the X axis, it would look like this:
local newOffset = Vector3.new(offset.X * percentage, 0, 0)
Final Step: Continue with how you normal made the offset, but instead of the default vector, use the new one.