I have a top down view for my camera which basically “detaches” it from the character and makes it draggable. This is probably causing issues however as I need to tween the camera for certain actions. Instead of tweening between Point A to Point B AND setting the position of the camera to Point B, it instead does a sort of spin and keeps the camera position at Point A (I need help implementing this as well)
I’ve tried multiple things to fix this, from disabling the RenderStep during the tween, to updating the cameraPos variable.
The camera is a modified version I found on the DevForum. I believe it might be something to do with CFrame.new(cameraPos, Vector3.new()) on this line:
camera.CFrame = CFrame.new(cameraPos, Vector3.new()) * zAngle * CFrame.new(-moved.X, moved.Y, zoomAmount) * xAngle * yAngle
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = 5
local mouse = LocalPlayer:GetMouse()
-----------------------CAMERA SETTINGS-----------------------
local dragSpeed = 7
local canZoom = true
local zoomSpeed = 50
local zoomMin = 0
local zoomMax = 2400
local moveArea = Vector2.new(175, 175)
----------------------MOVEMENT FUNCTION----------------------
local isDragging = false
local oldMousePos = Vector2.zero
local zoomAmount = math.clamp(10, zoomMin, zoomMax)
local movedAmount = Vector2.zero
local function MouseButtonDown()
isDragging = true
oldMousePos = UserInputService:GetMouseLocation()
end
local function MouseButtonUp()
isDragging = false
end
mouse.Button1Down:Connect(MouseButtonDown)
mouse.Button1Up:Connect(MouseButtonUp)
mouse.Button2Down:Connect(MouseButtonDown)
mouse.Button2Up:Connect(MouseButtonUp)
mouse.Move:Connect(function()
if isDragging then
movedAmount += (UserInputService:GetMouseLocation() - oldMousePos) * dragSpeed / 60
oldMousePos = UserInputService:GetMouseLocation()
end
movedAmount = Vector2.new(math.clamp(movedAmount.X, -moveArea.X, moveArea.X), math.clamp(movedAmount.Y, -moveArea.Y, moveArea.Y))
end)
mouse.WheelForward:Connect(function()
zoomAmount = zoomAmount - zoomSpeed > zoomMin and zoomAmount - zoomSpeed or zoomMin
end)
mouse.WheelBackward:Connect(function()
zoomAmount = zoomAmount + zoomSpeed > zoomMax and zoomMax or zoomAmount + zoomSpeed
end)
--mobile controls
-----------------------CAMERA FUNCTION-----------------------
local cameraPos = Vector3.new(0, 250, 0)
local xAngle = CFrame.Angles(math.rad(0), 0, 0)
local yAngle = CFrame.Angles(0, math.rad(0), 0)
local zAngle = CFrame.Angles(0, 0, (math.rad(0)))
local zoomed = zoomAmount
local moved = movedAmount
local function moveCamera(dt)
zoomed = zoomed + (zoomAmount - zoomed) * dt * zoomSpeed
moved = moved:Lerp(movedAmount, dt * dragSpeed)
camera.CFrame = CFrame.new(cameraPos, Vector3.new()) * zAngle * CFrame.new(-moved.X, moved.Y, zoomAmount) * xAngle * yAngle
end
RunService:BindToRenderStep("camera", Enum.RenderPriority.Camera.Value, moveCamera)
---------------------CAMERA TWEEN EVENTS---------------------
local cameraEvent = game:GetService("ReplicatedStorage"):WaitForChild("CameraPositionUpdater")
cameraEvent.Event:Connect(function(boolean, star)
if star then
local cameraTweenInfo = TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local cameraTween = TweenService:Create(camera, cameraTweenInfo, {CFrame = CFrame.new(star.CFrame.Position.X, 250, star.CFrame.Position.Z)})
cameraTween:Play()
cameraTween.Completed:Connect(function()
cameraEvent:Fire(true)
end)
end
end)