Essentially the issue is that ROBLOX’s vanilla MouseLock functionality allows users to clip their camera through walls if they get close enough, and thus they’ll be able to see through said walls. An example of this issue is shown here: https://www.youtube.com/watch?v=PNKIW21doe4
It’s an issue that has existed for years but the only potential solution, as outlined in the following posts, is to draw a ray between the camera focus point and the camera position and check to see if there is an obstruction.
https://devforum.roblox.com/t/anyone-have-a-good-method-for-camera-collisions/304990/2
In this user’s solution, he did exactly that, but I am unsure of how to incorporate a similar functionality into ROBLOX’s existing camera modules, as TG101 outlined here:
https://devforum.roblox.com/t/stop-shift-lock-looking-through-walls/27601/3
The code block TG101 refers to has been updated and reworked, but he is referring to line 148 of the ClassicCamera module:
if self:GetIsMouseLocked() and not self:IsInFirstPerson() then
-- We need to use the right vector of the camera after rotation, not before
local newLookCFrame = self:CalculateNewLookCFrame(overrideCameraLookVector)
local offset = self:GetMouseLockOffset()
local cameraRelativeOffset = offset.X * newLookCFrame.rightVector + offset.Y * newLookCFrame.upVector + offset.Z * newLookCFrame.lookVector
--offset can be NAN, NAN, NAN if newLookVector has only y component
if Util.IsFiniteVector3(cameraRelativeOffset) then
subjectPosition = subjectPosition + cameraRelativeOffset
end
My knowledge of camera manipulation is very limited and I would have no idea how to use raycasting to solve the issue while maintaining the core functionalities of shiftlock and without removing/effectively replacing the core components of the camera modules. As a result, I’ve barely touched the modules for fear of breaking things.
How can I use the example code in the first post and apply it to the solution outlined in the second?