So I’m trying to make a top-down camera that you can also drag around by pressing the right mouse button. This uses tweens
The problem is, I dont know how to make the camera go to where you drag the mouse to while holding the right mouse button.
This is the local script ive tried so far:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Hrp = Character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
local uis = game:GetService("UserInputService")
local rus = game:GetService("RunService")
local mouse = Player:GetMouse()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace.CamStartingPos.CFrame
local function mouseDrag()
uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
local mouseDelta = uis:GetMouseDelta()
local deltaX = mouseDelta.X
local deltaY = mouseDelta.Y
local tweenCamCframe = game:GetService("TweenService"):Create(camera,
TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0),
{CFrame = CFrame.new(Vector3.new(deltaX, workspace.CamStartingPos.Position.Y, deltaY))})
mouse.Move:Connect(function()
tweenCamCframe:Play()
end)
end
mouse.Button2Down:Connect(function()
rus:BindToRenderStep("MouseDrag", Enum.RenderPriority.Last.Value+1, mouseDrag)
end)
mouse.Button2Up:Connect(function()
rus:UnbindFromRenderStep("MouseDrag")
uis.MouseBehavior = Enum.MouseBehavior.Default
end)
Please help me with this, it is very important