Help with the a custom 360 camera script (Look up and down freely)

Making the camera type scriptable doesn’t break your script, it just disables most of the default camera behavior allowing you to script your own. I’m not experienced with camera manipulation but the link @CRAFTRONIX_457 sent should help you.

1 Like

I cannot find anything useful and anything that helps there.

1 Like

But is there still a way to make it work without scriptable or I can’t?

1 Like

Please refer to the post I linked above @CDDevelopment has mentioned about it already.

I did what u said, It works when I rotate. But not when I move my character. I cannot do this but what I can think of is I want to get its lookvector for head (in line 7), but if I added code at line 7 to renderstep, it will just override, glitches and cannot rotate. How can I do that?

Gyazo (also this camera is mainly for first person, char visible because I set the CameraMode to classic so you can see char.): https://gyazo.com/5bced98e872cca80b85bb926e2af901a

Code if needed:

wait(1)
local plr = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = plr.Character.Head.CFrame -- how do i get its lookvector? (Also for first person) and i didnt add it in renderstep because it will override the rotation  

rs.RenderStepped:Connect(function(step)
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter
	local delta = uis:GetMouseDelta()
	--print(delta)
	local x = delta.X
	local y = delta.Y
	cam.CFrame = cam.CFrame * CFrame.Angles(math.rad(-y),math.rad(-x),math.rad(0))
end)```

I still need help with this script

Try creating a new variable that describes the total orientation, then apply that to the head CFrame instead of the delta

Ok I will try doing that what u said.

I cannot do that because it would just glitch the camera rotation and I cannot really move it, I still will go for getting the mouse delta.

Make your script a local script, name it “Camera” and parent it to StarterPlayerScripts.

It is a local script and it is in StarterPlayerScripts.

What is the name of the local script? Also when using scriptable, you will have to set the camera subject to the player’s character’s humanoid.

Side note:
RenderStepped fired every render frame, which will fire at a rapid pace witch explains why it appears not to go.

I don’t think it’s necessary to know the name but the name is customCameraScript

It doesn’t work when i change camera subject to the player’s character’s humanoid.

The local script has to be named “Camera” in order to work. Have no idea why this is the case, but I think you should try it.

1 Like

I renamed to “Camera” but it didn’t work sadly. But what I’m saying is it’s working but I just don’t know how to make it focuses as a first person perspective view. Maybe for third person too if u can.

Any solutions for making it focus a head for my camera script?

A custom 360 camera script will require extensive CFrame knowledge only achievable through experimentation, the developer reference API and articles. Here is an example custom camera script I modified which does a 360 camera located at the players head through the following CFrame operations:

  1. Create a new CFrame positioned at the head
local headCf = plr.Character.Head.CFrame
local headCFPosOnly = CFrame.new(headCf.Position)
cam.CFrame = headCFPosOnly
  1. Add a CFrame rotation of the previous camera rotation CFrame without the position.
local currentCamRotationOnly = cam.CFrame-cam.CFrame.Position
cam.CFrame = headCFPosOnly*currentCamRotationOnly
  1. Then rotate the current camera along it’s relative axis via the mouse delta
local addRotation = CFrame.Angles(math.rad(-y),math.rad(-x),math.rad(0))
cam.CFrame = headCFPosOnly*currentCamRotationOnly*addRotation

By doing these steps you will get a really wonky 360 Camera where you can still see accessories but it works. For the third person, you will probably need very different CFrame operations but I hope this should serve as an example of the CFrame manipulation required for a custom camera script.

Overall local script Code
wait(1)
local plr = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = plr.Character.Head.CFrame

rs.RenderStepped:Connect(function(step)
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter
	local delta = uis:GetMouseDelta()
	--print(delta)
	local x = delta.X
	local y = delta.Y
	local addRotation = CFrame.Angles(math.rad(-y),math.rad(-x),math.rad(0))
	
	local headCf = plr.Character.Head.CFrame
	local headCFPosOnly = CFrame.new(headCf.Position)
	local currentCamRotationOnly = cam.CFrame-cam.CFrame.Position
	cam.CFrame = headCFPosOnly*currentCamRotationOnly*addRotation
end)
5 Likes

It’s fine, I can make my character’s CameraMode into LockFirstPerson.

I don’t necessary need for third person camera since but that’s also fine. Thanks anyway.

What changes would be needed for a third person camera? I have this issue and I cant lock the mouse.

1 Like

Why does my camera won’t rotate? I found something on YT a scripts. It was compatible with mobile except for the Rotation which i cannot rotate Left, Right, Backward, Frontward, Upward, Downward…

Can anybody here help me?

CODE

repeat wait() until game:GetService("Players").LocalPlayer.Character ~= CFrame
local runService = game:GetService("RunService")
local input = game:GetService("UserInputService")
local players = game:GetService("Players")

CanToggleMouse = {allowed = false; activationkey = Enum.KeyCode.E;}    ----------Keycode
CanViewBody = true 	
Sensitivity = 0.10
Smoothness = 0.07
FieldOfView = 80
HeadOffset = CFrame.new(0,0.7,0)

local cam = game.Workspace.CurrentCamera
local player = players.LocalPlayer
local m = player:GetMouse()
m.Icon = "http://www.roblox.com/asset/?id=10213989924"
local character = player.Character or player.CharacterAdded:wait()
local human = character.Humanoid
local humanoidpart = character.HumanoidRootPart

local head = character:WaitForChild("Head")
local CamPos,TargetCamPos = cam.CoordinateFrame.p,cam.CoordinateFrame.p 
local AngleX,TargetAngleX = 0,0
local AngleY,TargetAngleY = 0,0

local running = true
local freemouse = false
local defFOV = FieldOfView

local w, a, s, d, lshift = false, false, false, false, false


local easingtime = 0.1 
local walkspeeds = {
	enabled =		  true;
	walkingspeed =		18;
	backwardsspeed =	10;
	sidewaysspeed =		15;
	diagonalspeed =		16;
	runningspeed =		25;
	runningFOV=			85;
}

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 

function updatechar()
	
	for _, v in pairs(character:GetChildren())do
		if CanViewBody then
			if v.Name == 'Head' then
				v.LocalTransparencyModifier = 1
				v.CanCollide = false
				v.face.LocalTransparencyModifier = 1
			end
		else
			if v:IsA'Part' or v:IsA'UnionOperation' or v:IsA'MeshPart' then
				v.LocalTransparencyModifier = 1
				v.CanCollide = false
			end
		end
		if v:IsA'Accessory' then
			v:FindFirstChild('Handle').LocalTransparencyModifier = 1
			v:FindFirstChild('Handle').CanCollide = false
		end
		if v:IsA'Hat' then
			v:FindFirstChild('Handle').LocalTransparencyModifier = 1
			v:FindFirstChild('Handle').CanCollide = false
		end

	end
	
end

-- math, thx roblox wiki
function lerp(a, b, t)
	return a * (1-t) + (b*t)
end


---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 

input.InputChanged:connect(function(inputObject)
	
	if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
		local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness

		local X = TargetAngleX - delta.y 
		TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X 
		TargetAngleY = (TargetAngleY - delta.x) %360 
	end	
	
end)

input.InputBegan:connect(function(inputObject)
	
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then
		if inputObject.KeyCode == CanToggleMouse.activationkey then
			if CanToggleMouse.allowed and freemouse == false then
				freemouse = true
			else
				freemouse = false
			end
		end
	end
	
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then
		if inputObject.KeyCode == Enum.KeyCode.W then
			w = true
		end
		
		if inputObject.KeyCode == Enum.KeyCode.A then
			a = true
		end
		
		if inputObject.KeyCode == Enum.KeyCode.S then
			s = true
		end
		
		if inputObject.KeyCode == Enum.KeyCode.D then
			d = true
		end
		
		if inputObject.KeyCode == Enum.KeyCode.LeftShift then
			lshift = true
		end
	end
end)

input.InputEnded:connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then
		if inputObject.KeyCode == Enum.KeyCode.W then
			w = false
		end
		
		if inputObject.KeyCode == Enum.KeyCode.A then
			a = false
		end
		
		if inputObject.KeyCode == Enum.KeyCode.S then
			s = false
		end
		
		if inputObject.KeyCode == Enum.KeyCode.D then
			d = false
		end
		
		if inputObject.KeyCode == Enum.KeyCode.LeftShift then
			lshift = false
		end
	end
end)

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 

runService.RenderStepped:connect(function()
	 
	if running then
		updatechar()
		
		CamPos = CamPos + (TargetCamPos - CamPos) *0.28 
		AngleX = AngleX + (TargetAngleX - AngleX) *0.35 
		local dist = TargetAngleY - AngleY 
		dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist 
		AngleY = (AngleY + dist *0.35) %360
		cam.CameraType = Enum.CameraType.Scriptable
		
		cam.CoordinateFrame = CFrame.new(head.Position) 
		* CFrame.Angles(0,math.rad(AngleY),0) 
		* CFrame.Angles(math.rad(AngleX),0,0)
		* HeadOffset -- offset
		
		humanoidpart.CFrame=CFrame.new(humanoidpart.Position)*CFrame.Angles(0,math.rad(AngleY),0)
		else game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
	end

	if (cam.Focus.p-cam.CoordinateFrame.p).magnitude < 1 then
		running = false
	else
		running = true
		if freemouse == true then
			game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
		else
			game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
		end
	end
	
	if not CanToggleMouse.allowed then
		freemouse = false
	end
	
	cam.FieldOfView = FieldOfView
	
	if walkspeeds.enabled then
		if w and s then return end
		
		if w and not lshift then
			FieldOfView = lerp(FieldOfView, defFOV,easingtime)
			human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.walkingspeed,easingtime)
		elseif w and a then
			human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.diagonalspeed,easingtime)
		elseif w and d then
			human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.diagonalspeed,easingtime)
		elseif s then
			human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.backwardsspeed,easingtime)
		elseif s and a then
			human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.backwardsspeed - (walkspeeds.diagonalspeed - walkspeeds.backwardsspeed),easingtime)
		elseif s and d then
			human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.backwardsspeed - (walkspeeds.diagonalspeed - walkspeeds.backwardsspeed),easingtime)
		elseif d then
			human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.sidewaysspeed,easingtime)
		elseif a then
			human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.sidewaysspeed,easingtime)
		end	
		
		if lshift and w then
			FieldOfView = lerp(FieldOfView, walkspeeds.runningFOV,easingtime)
			human.WalkSpeed = lerp(human.WalkSpeed,human.WalkSpeed + (walkspeeds.runningspeed - human.WalkSpeed),easingtime)
			
		else
			wait(1)
			local plr = game.Players.LocalPlayer
			local uis = game:GetService("UserInputService")
			local rs = game:GetService("RunService")
			local cam = workspace.CurrentCamera
			cam.CameraType = Enum.CameraType.Scriptable
			cam.CFrame = plr.Character.Head.CFrame

			rs.RenderStepped:Connect(function(step)
				uis.MouseBehavior = Enum.MouseBehavior.LockCenter
				local delta = uis:GetMouseDelta()
				--print(delta)
				local x = delta.X
				local y = delta.Y
				local addRotation = CFrame.Angles(math.rad(-y),math.rad(-x),math.rad(0))

				local headCf = plr.Character.Head.CFrame
				local headCFPosOnly = CFrame.new(headCf.Position)
				local currentCamRotationOnly = cam.CFrame-cam.CFrame.Position
				cam.CFrame = headCFPosOnly*currentCamRotationOnly*addRotation
			end)
			
		end
	end
		
end)

I added this code from you @dthecoolest

wait(1)
local plr = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = plr.Character.Head.CFrame

rs.RenderStepped:Connect(function(step)
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter
	local delta = uis:GetMouseDelta()
	--print(delta)
	local x = delta.X
	local y = delta.Y
	local addRotation = CFrame.Angles(math.rad(-y),math.rad(-x),math.rad(0))
	
	local headCf = plr.Character.Head.CFrame
	local headCFPosOnly = CFrame.new(headCf.Position)
	local currentCamRotationOnly = cam.CFrame-cam.CFrame.Position
	cam.CFrame = headCFPosOnly*currentCamRotationOnly*addRotation
end)