Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make a camera similar to the one of Roblox Studio?

I need someone to make a camera script or teach me how to make a camera script that can be maneuvered by pressing W, A, S, or D. (the normal keys to move a character and the studio's camera) It also has to be able to be rotated with Right-Click & Drag.

Attempted Code:

local cam = workspace.CurrentCamera
--cam.CameraSubject = workspace.FreeCamera
cam.CameraType = "Custom"
local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local X = 0
local Y = 0
local Z = 0

--[[
	Camera Controls:
	W = Moves camera forward (+X)
	A = Moves camera left (-Z?)
	S = Moves camera backwards (-X)
	D = Moves camera right (+Z?)
--]]
-- Handle inputBegan event (when player first presses a key)

userInputService.InputBegan:connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.W then --Move forward
		X = X + 1
		cam.CoordinateFrame = CFrame.new(X, Y, Z)
	end
	if inputObject.KeyCode == Enum.KeyCode.S then --Move backwards
		X = X - 1		
		cam.CoordinateFrame = CFrame.new(X, Y, Z) 
	end
end)
 
-- Handle inputEnded event (when player releases a key)
userInputService.InputEnded:connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.W then --Reverses the X/Y/Z position because? I have no clue why! :D
		X = X - 1 
	end
	if inputObject.KeyCode == Enum.KeyCode.S then
		X = X + 1
	end
	
end)

I kinda gave up mid-way so, yeah there's a lot of errors in there.

If you can help me or know someone who can help me, please respond! I really need this. ~Chez_Guy :)

4 comments

0

Camera scripting should be done completely in Lua now as far as I'm aware, so I'd encourage you to check Roblox's code out.

0

@Avigant I dont know where the code for their camera system is

0

I believe L Shift + L will pull up freecam for the game dev only.

0

^ I remember there was a script for that somewhere in PlayerScripts I think. You could use that and edit the code to work for all players. Note that the script can be complex though.

2 answers

✓ Accepted answer

You can simply go into ROBLOX studio, and press Left Shift + P to go into "free-cam" mode. From there you can look at the contents of ROBLOX's script.

2 comments

0

Is the script a localscript named "ControlScript"?

0

This doesn't work.. :\

I just noticed this post, Sorry that it took so long for a proper answer. Anyway, I made what you were wondering about. I edited CloneTrooper1090's NoClip script, and here it is (local ofc)

	-- Basic Freecam Script
	-- You can move faster by holding the click button [setting below ! :) ]
local allowspeedmove = true
wait(1)

local c = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local userInput = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local starterPlayer = game:GetService("StarterPlayer")
--local util = LoadLibrary("RbxUtility")
--local camSync = util.CreateSignal()

local selected = false
local speed = 60
local lastUpdate = 0

local camera = Instance.new('Part', workspace)
camera.CanCollide = false
camera.Anchored = true
camera.Transparency = 1
camera.Name = 'FreeCam'
camera.Position = player.Character.HumanoidRootPart.Position + Vector3.new(0,5,0)
--rs:BindToRenderStep("CamSync",190,function ()
--	camSync:fire()
--end)

c.Changed:connect(function (property)
	if property == "CoordinateFrame" then
--		camSync:fire()
	end
end)

function getNextMovement(deltaTime)
	local nextMove = Vector3.new()
	-- Left/Right
	if userInput:IsKeyDown("A") or userInput:IsKeyDown("Left") then
		nextMove = nextMove + Vector3.new(-1,0,0)
	end
	if userInput:IsKeyDown("D") or userInput:IsKeyDown("Right") then
		nextMove = nextMove + Vector3.new(1,0,0)
	end
	-- Forward/Back
	if userInput:IsKeyDown("W") or userInput:IsKeyDown("Up") then
		nextMove = nextMove + Vector3.new(0,0,-1)
	end
	if userInput:IsKeyDown("S") or userInput:IsKeyDown("Down") then
		nextMove = nextMove + Vector3.new(0,0,1)
	end
	-- Up/Down
	if userInput:IsKeyDown("Space") or userInput:IsKeyDown("Q") then
		nextMove = nextMove + Vector3.new(0,1,0)
	end
	if userInput:IsKeyDown("LeftControl") or userInput:IsKeyDown("E") then
		nextMove = nextMove + Vector3.new(0,-1,0)
	end
	return CFrame.new( nextMove * (speed * deltaTime) )
end

function onSelected()
	local char = player.Character
	if char then
		local root = camera
		currentPos = root.Position
		selected = true
		lastUpdate = tick()
		c.CameraSubject = root
		player.Character.HumanoidRootPart.Anchored = true
		while selected do
			local delta = tick()-lastUpdate
			local look = (c.Focus.p-c.CoordinateFrame.p).unit
			local move = getNextMovement(delta)
			local pos = root.Position
			root.CFrame = CFrame.new(pos,pos+look) * move
			lastUpdate = tick()
			wait(0.01)
		--	camSync:wait()
		end
		player.Character.HumanoidRootPart.Anchored = false
		c.CameraSubject = player.Character.Humanoid
		root.Velocity = Vector3.new()
	end
end

function onDeselected()
	selected = false
end

local isOn = true
spawn(onSelected)

function onKeyPressed(_,state)
	if state == Enum.UserInputState.Begin then
		isOn = not isOn
		if isOn then
			onSelected()
		else
			onDeselected()
		end
	end
end

local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
	if allowspeedmove then speed = 120 end
end)
mouse.Button1Up:Connect(function()
	speed = 60
end)

function ResetCamera()
	camera.Position = player.Character.HumanoidRootPart.Position + Vector3.new(0,5,0)
end

game:GetService("ContextActionService"):BindAction("Noclip Toggle",onKeyPressed,false,"r")
game:GetService("ContextActionService"):BindAction("Reset Camera Position",ResetCamera,false,"z")

**Yes, I do know you aren't allowed to request things, but I made this anyway, and I wanted to share it with others who may need it. :)

1 comment

0

Thank you so much for this. I was having alot of trouble trying to recreate one that was even close to as comfy as the original one from the studio

This discussion is preserved as it was. New answers, comments, and votes are closed.