Camera thingy where if you hold down rmb you can move the camera by dragging your mouse, but i have the camera set up diagonally so it just moves in a X type of pattern when viewing from the camera, so i was wondering if there was a way to make the movements diagonal
Code
-- Variables
local RunService = game:GetService("RunService")
local uis = game:GetService('UserInputService')
local Ts = game:GetService("TweenService")
-- math and stuff --
local clamp = math.clamp
local cfa = CFrame.Angles
local rad = math.rad
local cfn = CFrame.new
local v3n = Vector3.new
-- --
local player = game:GetService("Players").LocalPlayer
local camera = game.Workspace.CurrentCamera
local mouse = player:GetMouse()
local IsHeldDown = false
local Debug = true
local View = 25
local MinView = 10
local MaxView = 50
local DownCF = CFrame.Angles(0,rad(-45),0) * CFrame.Angles(rad(-45),0,0)
local CurrentPos = v3n(0,0,0)
local Connection1
local Connection2
local part1 = Instance.new("Part", workspace); part1.Anchored = true; part1.Size = Vector3.new(1,1,1); part1.CanCollide = false; part1.CanQuery = false; part1.CanTouch = false
local part2 = part1:Clone(); part2.Parent = workspace
local part3 = part1:Clone(); part3.Parent = workspace
part1.Transparency = 0.8; part2.Transparency = 0.8; part3.Transparency = 0.8;
part1.Color = Color3.new(1,0,0); part2.Color = Color3.new(0,1,0); part3.Color = Color3.new(0,0,1)
-- Functions
local function Main()
Connection1 = RunService.RenderStepped:Connect(function()
local tH = (clamp(View,MinView,MaxView))/5
local mP = mouse.Hit.Position
local CamCFrame = cfn(v3n(CurrentPos.X, CurrentPos.Y + clamp(View, MinView, MaxView), CurrentPos.Z)) * DownCF
if IsHeldDown then
local MD = uis:GetMouseDelta()
CamCFrame += v3n(MD.Y*.25,0,MD.X*.25)
CurrentPos += v3n(MD.Y*.25,0,MD.X*.25)
end
if Debug then
part1.Position = mP
part2.Position = CurrentPos
part3.Position = CamCFrame.Position - v3n(0, clamp(View, MinView, MaxView), 0)
end
Ts:Create(camera, TweenInfo.new(.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),{CFrame = CamCFrame}):Play()
end)
end
local function Main2()
coroutine.resume(coroutine.create(function()
Connection2 = RunService.RenderStepped:Connect(function()
if IsHeldDown then
uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
else
uis.MouseBehavior = Enum.MouseBehavior.Default
end
end)
end))
end
-- Main
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
mouse.WheelForward:Connect(function()
View = clamp((View - 4), 10, 50)
end)
mouse.WheelBackward:Connect(function()
View = clamp((View + 4), 10, 50)
end)
uis.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton2 then
IsHeldDown = true
end
end)
uis.InputEnded:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton2 then
IsHeldDown = false
end
end)
Main2()
Main()