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

Third person camera?

I'm trying to create a third person camera and cannot get it to rotate around the player properly. What I am doing is taking the mouse.Delta as a way to add or subtract the angle of rotation. My problem is it will not rotate around the player, and if I allow the y axis to be rotated, it will be able to be rotated to unusable angles (It can flip upside-down and whatnot) I have tried to add and subtract the Z according to the rotation amount but that probed unreliable. I also tried to use CFrame:toObjectSpace() and couldn't get that to work.

My code:

--Camera update--
	game:GetService("RunService").RenderStepped:connect(function()
		if player.Self == nil then return end
		cam.CoordinateFrame = player.Self.Head.CFrame*CFrame.new(0,1,7)*camera.offset
	end)	
--Input--
	inp.InputChanged:connect(function(io)
		if io.UserInputType == Enum.UserInputType.MouseMovement then
			camera.offset = camera.offset*CFrame.Angles(0,-math.rad(io.Delta.x/10),0)
		end
	end)

3 comments

0

Why don't you NOT use RenderStepped? And what is cam? You haven't named it.

0

If I didn't use RenderStepped the camera would be laggy as it updated. And I have named it in the code before. cam = player.Camera, player.Camera = game.Workspace.CurrentCamera.

1 answer

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