So i’m making a camera that will look at the character in a certain position.
The problem is that when you go to the zone where the camera changes, camera flicks for 0.5 seconds. Does anyone know why this is happening and how to fix it?
So i’m making a camera that will look at the character in a certain position.
The problem is that when you go to the zone where the camera changes, camera flicks for 0.5 seconds. Does anyone know why this is happening and how to fix it?
can you provide your script?
ignore
--// SERVICES
local players = game:GetService("Players")
local runService = game:GetService('RunService')
local ContextActionService = game:GetService("ContextActionService")
--// VARIBALES
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera
local partThatChangesStuff = require(script:WaitForChild"CameraZones")
local cameraPart = script:WaitForChild"CameraObject"
local step
ContextActionService:BindActionAtPriority("RightMouseDisable", function()
return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.Medium.Value, Enum.UserInputType.MouseButton2)
ContextActionService:BindActionAtPriority("DisableArrowKeys", function()
return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.Up, Enum.KeyCode.Down, Enum.KeyCode.Left, Enum.KeyCode.Right)
local customCameraEnabled = false;
local function enableCustomCamera()
customCameraEnabled = true
cam.CFrame = hrp.CFrame
if cameraPart and cameraPart.Value then
local goal = cameraPart.Value.CFrame
step = runService.Stepped:Connect(function()
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = CFrame.lookAt(cameraPart.Value.Position + Vector3.new(0,0,0), hrp.Position)
cam.CFrame = cam.CFrame:Lerp(goal, 0.25)
end)
end
end
local function disableCustomCamera()
customCameraEnabled = false
step:Disconnect()
cam.CameraType = Enum.CameraType.Custom
end
local function isPlayerInCustomRoom()
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Whitelist
params.FilterDescendantsInstances = {partThatChangesStuff}
local result = workspace:Raycast(hrp.Position, Vector3.new(0,-10,0), params)
if (result) then
if result.Instance:FindFirstChild"CameraPart" then
cameraPart.Value = result.Instance:FindFirstChild"CameraPart"
return true
end
return false
end
return false
end
while task.wait() do
if (isPlayerInCustomRoom()) then
if (not customCameraEnabled) then
enableCustomCamera()
end
else
if (customCameraEnabled) then
disableCustomCamera()
end
end
end
full script, too lazy to cut off-topic stuff
Changing the camera type is what is causing the flick I’m pretty sure.
The camera gets changed to scriptable
The rotation and everything of the camera is reset due to cameratype being changed (The flick)
The CFrame logic sets the camera CFrame
It doesn’t show up when you change it back because roblox by default instantly converts it back to the set position, which wouldn’t cause the CFrame to revert then be set again
I think you could either use TweenService instead lerping OR
make it change the CFrame before and after changing the camera type maybe?
(I think it would work, I don’t know for sure)
Tweenservice helped. Thanks for the explanation