-
What do you want to achieve?
I want to have an over the shoulder camera much like the one in Base battles (Link) -
What is the issue?
The camera goes through walls and the ground. -
What solutions have you tried so far?
I have done a bit of coding and have a raycast in place. The raycast shoots a ray from the HumanoidRootPart to where the camera should be to see if any wall is in the way. That works!
But when I try to position the camera. It goes away like 30 studs away. I dont understand why.
I have this code in the renderstepped function.
local startCFrame = CFrame.new(Root.CFrame.Position) * CFrame.Angles(0, math.rad(CameraAngleX), 0) * CFrame.Angles(math.rad(CameraAngleY), 0, 0)
local cameraCFrame = startCFrame:PointToWorldSpace(CameraOffset)
local CameraWallCheck = workspace:Raycast(Root.Position, (Root.Position - cameraCFrame) * -1, params)
local cameraFocus = startCFrame:PointToWorldSpace(Vector3.new(CameraOffset.X, CameraOffset.Y, -10000))
if CameraWallCheck then
local hitPos = Root.CFrame:PointToWorldSpace(CameraWallCheck.Position)
cameraCFrame = startCFrame:PointToWorldSpace(hitPos)
end
Camera.CFrame = CFrame.lookAt(cameraCFrame, cameraFocus)