so, recently I began making an camera system like u can select 2 towers and yea, but everything got wrong quickly after I tried to make like, when pressing left arrow you’ll get the main camera or the current camera
to look at the current camera part.
I took a few tries but I could move the camera cframe and things.
elseif input.KeyCode == Enum.KeyCode.Left then
currentCameraIndex = currentCameraIndex - 1
if currentCameraIndex < 1 then
currentCameraIndex = #cameras
end
local previousCameraPart = cameraFolder:FindFirstChild(tostring(currentCameraIndex))
if previousCameraPart then
local newMainOrientation = CFrame.new(mainPart.Position, previousCameraPart.Position)
mainPart.CFrame = newMainOrientation
local targetRotation = previousCameraPart.CFrame:vectorToWorldSpace(Vector3.new(1, 0, 0))
local rotation = mainPart.CFrame:pointToObjectSpace(targetRotation)
local rotationY = math.atan2(rotation.X, rotation.Z)
local newCameraCFrame = cameraFolder:FindFirstChild(tostring(currentCameraIndex)).CFrame * CFrame.Angles(0, rotationY, 0)
local transitionTime = 0.5
TweenService:Create(currentCamera, TweenInfo.new(transitionTime), { CFrame = newCameraCFrame }):Play()
end
elseif input.KeyCode == Enum.KeyCode.Right then
currentCameraIndex = currentCameraIndex + 1
if currentCameraIndex > #cameras then
currentCameraIndex = 1
end
local nextCameraPart = cameraFolder:FindFirstChild(tostring(currentCameraIndex))
if nextCameraPart then
local newMainOrientation = CFrame.new(mainPart.Position, nextCameraPart.Position)
mainPart.CFrame = newMainOrientation
local targetRotation = nextCameraPart.CFrame:vectorToWorldSpace(Vector3.new(1, 0, 0))
local rotation = mainPart.CFrame:pointToObjectSpace(targetRotation)
local rotationY = math.atan2(rotation.X, rotation.Z)
local newCameraCFrame = currentCamera.CFrame * CFrame.Angles(0, rotationY, 0)
local transitionTime = 0.5
TweenService:Create(currentCamera, TweenInfo.new(transitionTime), { CFrame = newCameraCFrame }):Play()
end
and if someone is wondering I made the up and down keys that are working ( fortunately ).
elseif input.KeyCode == Enum.KeyCode.Up then
local currentCameraPart = cameraFolder:FindFirstChild(tostring(currentCameraIndex))
if currentCameraPart then
if mainPart then
local targetCFrame = currentCameraPart.CFrame
local transitionTime = 0.5
TweenService:Create(currentCamera, TweenInfo.new(transitionTime), { CFrame = targetCFrame }):Play()
end
end
elseif input.KeyCode==Enum.KeyCode.Down then
if mainPart then
local transitionTime = 0.5
TweenService:Create(currentCamera, TweenInfo.new(transitionTime), { CFrame = mainPart.CFrame }):Play()
end