Isometric Draggable Camera

I want to make a draggable isometric game like clash of clans
like this: https://youtu.be/DaZWdT003AI?si=aRN9_0CrPRn556VV&t=50

here my attempt to make it by using a script from similar topic:

local run = game:GetService'RunService'
local uis = game:GetService'UserInputService'

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local cam = workspace.Camera
cam.CameraType = Enum.CameraType.Scriptable

local speed = .2 -- Speed when dragging
local lockMouse = true -- locks mouse when dragging
local origin = CFrame.lookAt(Vector3.new(0,10,0), Vector3.new()) -- Where the camera will start
local moved = Vector2.zero -- How much the camera has moved

local dragging = false
local oldMousePos = Vector2.zero
mouse.Button1Down:Connect(function()
	dragging = true
	oldMousePos = uis:GetMouseLocation()
end)
mouse.Button1Up:Connect(function()
	dragging = false
	uis.MouseBehavior = Enum.MouseBehavior.Default
	moved = Vector2.zero -- Reset the moved value
end)

run.RenderStepped:Connect(function(dt)
	if dragging then
		if lockMouse then
			uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
			moved += uis:GetMouseDelta()*speed*dt
		else
			local currentMousePos = uis:GetMouseLocation()
			if currentMousePos ~= oldMousePos then -- Check if the mouse has moved
				moved += (currentMousePos - oldMousePos)*speed*dt
				oldMousePos = currentMousePos
			end
		end
	end
	local isoView = CFrame.new(cam.CFrame.p, cam.CFrame.p + Vector3.new(1, -1, -1))
	cam.CFrame = isoView * CFrame.new(-moved.X*speed, 0, moved.Y*speed)
end)

The X axis looks fine but the problem is the Z axis
It moves forward and backward in the direction where camera looking

not in the same Z Axis position it is in
if u understand
just check the example vid link on top to seee what i mean

2 Likes

Well, that’s a late response but if you still need help with this I run in the same issue today, I fixed it by doing that:

-- Get "FrontVector" by using look at LookVector and setting the Y position to the original camera position
local frontVector   = (camera.CFrame + camera.CFrame.LookVector).Position
frontVector = Vector3.new(frontVector.X, camera.CFrame.Position.Y, frontVector.Z)

local cameraCframe = CFrame.lookAt(camera.CFrame.Position, frontVector)
camera.CFrame = camera.CFrame + (cameraCframe.RightVector * -delta.X) + (cameraCframe.LookVector * delta.Y)

You can easily adapt it to your code :slight_smile:

Appreciate it
but I already fixed the issue :slight_smile:

1 Like