Basic top down birds eye view RTS game camera

I started working on this small RTS game for fun as I started getting sick of my other game which was a Roguelite that I had run out of ideas for as of now. With that being said I have this goofy little RTS camera system thats very choppy and janky but can hopefully help someone whos trying to make a prototype game with the same theme as i am.

Script should be inserted into StarterPlayerScripts and Players.CharacterAutoLoads should be disabled for it to function

local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
local test = 1
local userInput = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")


--[[Changeable elements]]
-- pX, pY, and pZ determine starting location and also camera elevation (in this case its 70 studs up in the air)
local pX = 0
local pY = 70
local pZ = 0
-- angleDown refers to the angle at which the camera points down to the ground, the higher the number the steeper the view
local angleDown = 0.90


local forward = false
local left = false
local right = false
local back = false


cam.CFrame = CFrame.new(pX, pY, pZ)*CFrame.Angles(-angleDown, 0, 0)

userInput.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		forward = true
		while forward do
			pZ -= 1
			tweenService:Create(cam, TweenInfo.new(0.000000001, Enum.EasingStyle.Linear), {CFrame = CFrame.new(pX, pY, pZ)*CFrame.Angles(-0.90, 0, 0)}):Play()
			wait(0.0000000000001)
			userInput.InputEnded:Connect(function(input)
				if input.KeyCode == Enum.KeyCode.W then
					forward = false
				end
			end)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.S then
		back = true
		while back do
			pZ += 1
			tweenService:Create(cam, TweenInfo.new(0.000000001, Enum.EasingStyle.Linear), {CFrame = CFrame.new(pX, pY, pZ)*CFrame.Angles(-0.90, 0, 0)}):Play()
			wait(0.0000000000001)
			userInput.InputEnded:Connect(function(input)
				if input.KeyCode == Enum.KeyCode.S then
					back = false
				end
			end)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.A then
		left = true
		while left do
			pX -= 1
			tweenService:Create(cam, TweenInfo.new(0.000000001, Enum.EasingStyle.Linear), {CFrame = CFrame.new(pX, pY, pZ)*CFrame.Angles(-0.90, 0, 0)}):Play()
			wait(0.0000000000001)
			userInput.InputEnded:Connect(function(input)
				if input.KeyCode == Enum.KeyCode.A then
					left = false
				end
			end)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.D then
		right = true
		while right do
			pX += 1
			tweenService:Create(cam, TweenInfo.new(0.000000001, Enum.EasingStyle.Linear), {CFrame = CFrame.new(pX, pY, pZ)*CFrame.Angles(-0.90, 0, 0)}):Play()
			wait(0.000000000001)
			userInput.InputEnded:Connect(function(input)
				if input.KeyCode == Enum.KeyCode.D then
					right = false
				end
			end)
		end
	end
end)

heres how it looks in game:

7 Likes