Camera Occlusion

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the camera to not phase through walls when being pushed against them.

  2. What is the issue? Include screenshots / videos if possible!
    I believe the issue is caused by my camera offset. (Issue shown below)

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried modifying the camera module but that didn’t work.

Any help is welcome, thanks!

1 Like

I forgot to mention this but i’m not using roblox’s built in shift lock, i’m using LockCenter in a script.

I don’t know if it would work but you could try something with raycasts and then setting the CameraOffset (in the humanoid) away from the wall

1 Like

I’m about to go to sleep, but I’ll totally try that in the morning. Thanks for the suggestion!

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. :tada::tada::tada::tada:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.