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

Free cam, camera CFRAME glitchy?

player = game.Players.LocalPlayer
mouse = player:GetMouse()
camera = game.Workspace.CurrentCamera
UserInputService = game:GetService("UserInputService")

wait(2)

game.Players.LocalPlayer.Character:Destroy()

camera.CameraType = "Scriptable"
camera.CoordinateFrame = CFrame.new(0,18,0)

keys = {}

mouse.KeyDown:connect(function(key) keys[key] = true end)
mouse.KeyUp:connect(function(key) keys[key] = nil  end)



 
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.InputChanged:connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
		print("delta is (" .. tostring(inputObject.Delta.x) .. ", " ..  tostring(inputObject.Delta.y) .. ")")
		camera.CoordinateFrame = CFrame.Angles(0,math.rad(-inputObject.Delta.x),0) * CFrame.Angles(math.rad(-inputObject.Delta.y),0,0) * camera.CoordinateFrame 

-- glitches here
	end
end)

game:GetService("RunService").RenderStepped:connect(function()

--Basic Moving


if keys["w"] then
camera.CoordinateFrame  = camera.CoordinateFrame * CFrame.new(0,0,-1)	
end

if keys["s"] then
camera.CoordinateFrame  = camera.CoordinateFrame * CFrame.new(0,0,1)	
end

if keys["a"] then
camera.CoordinateFrame  = camera.CoordinateFrame * CFrame.new(-1,0,0)	
end

if keys["d"] then
camera.CoordinateFrame  = camera.CoordinateFrame * CFrame.new(1,0,0)	
end


--Basic Moving
	
end)

If you use it and look around, its very weird and "rolls"

1 answer

This should give you the same camera as the one you use in studio. That means that you won't have to code controls for it. The control keys are WASDQE

Put this in a LocalScript in Game.StarterPlayer.StarterPlayerScripts

local player = game.Players.LocalPlayer
wait(1)
Camera = game.Workspace.CurrentCamera
game:GetService('RunService').RenderStepped:connect(function()
Camera.CameraType = 'Fixed'
Camera.CameraSubject = workspace
end)

And put this in a Script in Game.Workspace

function remove_character(child)
if game.Players:playerFromCharacter(child) ~= nil then
	repeat wait() until child:findFirstChild("Torso")
	game.Players:playerFromCharacter(child).Character = nil
end end

game.Workspace.ChildAdded:connect(remove_character)
for x, v in pairs(game.Workspace:getChildren()) do
	remove_character(v)
end

The Script removes the players Character as soon as it is created. The LocalScript changes the camera to

Camera.CameraType = 'Fixed' Camera.CameraSubject = workspace

every time a new frame is rendered. This is important because without it Roblox would automatically reset it to the defaults.

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