so i have a local script. i’m trying to use ZonePlus to create dynamic camera zones. the camera’s CFrame is being changed, but there is no linear interpolation. i don’t want to use tweens, that would require me to create and destroy a tween. create and destroy, create and destroy.
here’s what i have right now.
my local script:
-- uses ZonePlus by ForeverHD
local currentCamera = workspace.CurrentCamera
local tweenService = game:GetService("TweenService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local zonePlus = require(replicatedStorage:WaitForChild("Zone"))
local ambienceFolder = workspace:FindFirstChild("ambienceFolder")
local localPlayer = game:GetService("Players").LocalPlayer
local cameraPartFolder = workspace:FindFirstChild("cameraParts")
local zoneController = require(replicatedStorage.Zone.ZoneController)
local soundService = game:GetService("SoundService")
local runService = game:GetService("RunService")
local lerpFactor = 0.08
local runServiceConnection
local ambientParts = {
ambienceFolder:WaitForChild("calmSeaside"),
ambienceFolder:WaitForChild("consumerism"),
ambienceFolder:WaitForChild("sunset"),
ambienceFolder:WaitForChild("creepyFog")
}
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut)
local propertyTable = {Volume = 1}
local propertyTable2 = {Volume = 0}
for _, zonePart in ipairs(ambientParts) do
local ambientZone = zonePlus.new(zonePart)
local audioFile = soundService.ambientSounds:WaitForChild(tostring(zonePart.Name)) -- works now, yay!
-- ambientZone:relocate()
ambientZone:bindToGroup("ambientAreas")
ambientZone.localPlayerEntered:Connect(function()
print(zonePart.Name, "was entered")
local tween = tweenService:Create(audioFile, tweenInfo, propertyTable):Play()
local camPart = cameraPartFolder:FindFirstChild("c_"..tostring(zonePart.Name))
if camPart then
-- this updates the camera's CFrame. odd.
currentCamera.CameraType = Enum.CameraType.Scriptable
runServiceConnection = runService.RenderStepped:Connect(function()
currentCamera.CFrame = camPart.CFrame
local targetPart = localPlayer.CharacterAdded:Wait().PrimaryPart
local lookAtPosition = targetPart.Position
local currentPosition = camPart.Position
local lookAtCFrame = CFrame.new(currentPosition, lookAtPosition)
camPart.CFrame = camPart.CFrame:Lerp(lookAtCFrame, lerpFactor)
print("cframe updated") -- this never prints!
end)
print("corresponding camera part found")
end
end)
ambientZone.localPlayerExited:Connect(function() -- no issues here.
print(zonePart, "was exited")
if runServiceConnection then
runServiceConnection:Disconnect()
end
currentCamera.CameraType = Enum.CameraType.Custom
local tween = tweenService:Create(audioFile, tweenInfo, propertyTable2):Play()
end)
end
local dictionary = {
onlyEnterOnceExitedAll = true,
}
zoneController.setGroup("ambientAreas", dictionary)