Hey everyone!
I’m trying to create a silent hill inspired camera system and so far it has been going well, however i have ran into an issue.
Whenever the camera switches from one angle to another, it makes my roblox character walk in a different direction than before. Below im going to post a video showcasing the issue.
Below i’m also going to paste the script im using. Any help is appreciated!!!
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local Head = Character:WaitForChild("HumanoidRootPart")
local TouchesFolder = workspace:WaitForChild("Touches")
local CamsFolder = workspace:WaitForChild("Cams")
local touchCameraPairs = {
["Touch1"] = "Cam1",
["Touch2"] = "Cam2",
}
local currentCameraPart = nil
local spawnWithSpawnCam = false -- Set it to "true" if you wanna Spawn with SpawnCam
--and false if you wanna spawn with normal Roblox Camera
local function updateCamera()
if currentCameraPart then
local cameraPart = CamsFolder[currentCameraPart]
if cameraPart then
local cameraPosition = cameraPart.Position
local lookAtPosition = Head.Position
local newLookVector = (lookAtPosition - cameraPosition).unit
local newCFrame = CFrame.new(cameraPosition, cameraPosition + newLookVector)
Camera.CFrame = newCFrame
end
else
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Character
end
end
local function onTouch(touchPart)
if touchPart.Name == "End" then
currentCameraPart = nil
else
local cameraPartName = touchCameraPairs[touchPart.Name]
if cameraPartName then
currentCameraPart = cameraPartName
end
end
end
for touchPart, _ in pairs(touchCameraPairs) do
local part = TouchesFolder:FindFirstChild(touchPart)
if part then
part.Touched:Connect(function()
onTouch(part)
end)
end
end
local endPart = TouchesFolder:FindFirstChild("End")
if endPart then
endPart.Touched:Connect(function()
onTouch(endPart)
end)
end
if spawnWithSpawnCam then
currentCameraPart = "SpawnCam"
end
updateCamera()
game:GetService("RunService").RenderStepped:Connect(function()
updateCamera()
end)