Hello, so I am having a problem with my script for a over the shoulder system i got, its clipping through walls when i get close to them and i have no clue how to fix this, script below.
local players = game:GetService("Players")
local contextactionservece = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local UserInput = game:GetService("UserInputService")
--------
local Camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local cameraOffset = Vector3.new(1.5, 2, 8)
-----------------------------------------------------------------------
player.CharacterAdded:Connect(function(character)
-- actual camera function, i.e positioning
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local cameraAngleX = 0
local cameraAngleY = 0
--humanoid.AutoRotate = false
local function playerInput (actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Change then
cameraAngleX -= inputObject.Delta.X
cameraAngleY = math.clamp(cameraAngleY - inputObject.Delta.Y * 0.4, -75, 75)
end
end
contextactionservece:BindAction("PlayerInput", playerInput, false, Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)
RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
local startCFrame = CFrame.new(rootPart.CFrame.Position) * CFrame.Angles(0, math.rad(cameraAngleX), 0) * CFrame.Angles(math.rad(cameraAngleY), 0, 0)
local cameraCFrame = startCFrame:PointToWorldSpace(cameraOffset)
local cameraFocus = startCFrame:PointToWorldSpace(Vector3.new(cameraOffset.X, cameraOffset.Y, -1000000))
Camera.CFrame = CFrame.lookAt(cameraCFrame, cameraFocus)
--local lookingCFrame = CFrame.lookAt(rootPart.Position, Camera.CFrame:PointToWorldSpace(Vector3.new(0, 0, -1000000)))
--rootPart.CFrame = CFrame.fromMatrix(rootPart.Position, lookingCFrame.XVector, rootPart.CFrame.YVector)
--
end)
end)
------------------------------------------------------------------------
local function focusControl(actionName, inputState, inputObject)
--mouse control / locking center
if inputState == Enum.UserInputState.Begin then
Camera.CameraType = Enum.CameraType.Scriptable
UserInput.MouseBehavior = Enum.MouseBehavior.LockCenter
--UserInput.MouseIconEnabled = false //MAKE MOUSE GO ICON GO POOF
contextactionservece:UnbindAction("FocusControl")
end
end
contextactionservece:BindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)