Hey. I’ve been working on my Custom Camera System, but I ran into a minor problem. I create a Ray Cast from the HumanoidRootPart of the player’s character towards the Camera’s CFrame to detect if there is any object to block a through-wall camera basically.
Though the script doesn’t work properly at all.
Video of the issue:
Code:
local players = (game:GetService("Players"));
local localPlayer = (players.LocalPlayer);
local character = (localPlayer.Character or localPlayer.CharacterAdded:Wait());
local camera = {}
camera.__index = camera
function camera.new()
local self = {
origin = (character:WaitForChild("HumanoidRootPart"));
camera = (workspace.CurrentCamera);
zoomInfluence = (15 / 7);
zoom = (-15)};
return setmetatable(self, camera)
end;
-- // I have cut all the functions except the related ones.
function camera:CreateRayFromOrigin(cframe)
local rayCastParams = RaycastParams.new();
rayCastParams.FilterDescendantsInstances = {self.origin.Parent}
rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist
return (workspace:Raycast(self.origin.CFrame.Position, cframe.Position, rayCastParams))
end;
function camera:CalculateCameraCFrame()
local cframe = (CFrame.new(self.origin.CFrame.Position) * (self.camera.CFrame - self.camera.CFrame.Position) * CFrame.new(0, 0, -self.zoom));
local rayCastResult = (self:CreateRayFromOrigin(cframe));
if not (rayCastResult) or (rayCastResult) and (rayCastResult.Instance:IsDescendantOf(character)) then
return (CFrame.lookAt(cframe.Position, self.origin.CFrame.Position));
elseif (rayCastResult) and not (rayCastResult.Instance:IsDescendantOf(character)) then
return (CFrame.lookAt(rayCastResult.Position, self.origin.CFrame.Position));
end
end;
Help from anybody would be appreciated.