Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to fix problems when moving camera to collide point in ray cast?

I have a fully functional third person camera script, everything works fine, except for one aspect, and that is the popper part of my script. I decided to use raycast position to identify where to move camera to if it collides with a part. Downside is, it works almost perfectly, but the camera just slightly clips through part, which in turns ruins what i wanted. Heres the popper part of the script, and is needed to note all of the function works as intended, only the popper wont work.

Camera.Focus= Character.PrimaryPart.CFrame
local Direction = (cameraCFrame.p-Character.Head.Position).Unit*((cameraPos)).Magnitude
local CheckRay = Ray.new(Character.Head.Position, Direction)
local Part, Position = game.Workspace:FindPartOnRay(CheckRay,Character,false,true)
if Part then
	--local Distance = Camera:GetLargestCutoffDistance({Character}), decided not working well either.
	local x,y,z= Camera.CFrame:ToEulerAnglesXYZ()
	Camera.CFrame= CFrame.new(Position)*CFrame.Angles(x,y,z)
end

If you need the full script, i would be glad to post it here, seeing as i most likely will make a public script. Thank you!

1 answer

Received answer on roblox dev forums. For those who seek this, here is new modified script.

Camera.Focus= Character.Head.CFrame
local Direction = (cameraCFrame.p-Character.Head.Position).Unit*((cameraPos)).Magnitude
local CheckRay = Ray.new(Character.Head.Position, Direction)
local Part, Position, face = game.Workspace:FindPartOnRay(CheckRay,Character,false,true)
if Part then
	local x,y,z= Camera.CFrame:ToEulerAnglesXYZ()
	Camera.CFrame= CFrame.new(Position)*CFrame.Angles(x,y,z)
	Camera.CFrame= Camera.CFrame+face*.15
end

By simple multiplying the final cframe, with the face normal, you can get the popper working! In my case, multiplying by .15 got it working, could be lower for you(or higher), just dont go over .5, might be far, far off.

This discussion is preserved as it was. New answers, comments, and votes are closed.