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

Im making a 3rd Person Camera but I cannot make the camera rotate. any help ?

Im making an over shoulder 3rd person camera styled game.

I Correctly Positioned the camera Over the shoulder of the character and enabled mouse lock on every frame.

when I use UseInputService:GetMouseDelta , it returns me the distance the mouse pixels move on the last rendered frame. (Its a Vector2)

deltaX is that vector2's Y Value

and deltaY is that vector2's Y Value

I setted RotX [RotationX] to delta X and RotY [RotationY] to delta Y

So I get both of the Rot Values [Rotation Values] And then I try to add them to the camera's Current Rotation and divide them by 120 Becuase The Values mainly consist of whole Numbers.

But here is the problem ! The Camera Moves when I move my mouse , But It moves All Over The place like the camera is being shaken.

Can Please someone help me with this camera rotation part? thanx ! :D

Note That : This is a local Script in Starter Character Scripts !

local player = game.Players.LocalPlayer

local char = script.Parent

local hum = char:WaitForChild("Humanoid")

local root = char:WaitForChild("HumanoidRootPart")

---//// Services !!! --- [Start]

local uis = game:GetService("UserInputService")

local runs = game:GetService("RunService")----We Need this So it handles things every frame !

---//// Services !!! ---  [END]

local camera = game.Workspace.CurrentCamera-- The Camera


local mouse = player:GetMouse() ---- Returns the players mouse !


local RotX , RotY = 0 , 0 ----The Rotation Axis For the Camera !

---- Its Defualt Position is set to ;;;//// X/ 3.555, Y/ 3, Z/ 6.5   (so it goes over the player's shoulder like a 3rd person game !

local XOffset = 3.555

local YOffset = 3

local ZOffset = 6.5


----/// Listens For Mouse Movements !  (So It Can Update The RotX and RotY Values !//---

uis.InputChanged:Connect(function(input)
	
	if input.UserInputType == Enum.UserInputType.MouseMovement then


		
		local vec2 = uis:GetMouseDelta()
		
		
		warn("X : "..vec2.X.."/ Y : "..vec2.Y)
		
		RotX = vec2.X
		
		RotY = -vec2.Y
		
	
		
		
	end
	
	
	
	
	
end)


----// Create The Function To fire per every frame !//---

function OnStepped()---This Will Update EVery Frame
	
	
	
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter
	
	print("X/ "..XOffset..", Y/ ".. YOffset..", Z/ ".. ZOffset)
	
	
	camera.CFrame = root.CFrame * CFrame.new(XOffset,YOffset,ZOffset) 
	
		camera.CFrame = camera.CFrame * CFrame.fromEulerAnglesXYZ(RotY/120,0,0) * CFrame.fromEulerAnglesXYZ(0,-RotX/120,0)

	
	
	
	print(RotX/120)
	print(RotY/120)
	
end


runs.RenderStepped:Connect(OnStepped)---Will Fire Per Every Frame !



2 comments

0

you can try this script out yourselves too !

0

Just edited line 76 ... still doesn't work ... ! :(

1 answer

Way 1 Put this in Starter Player Scripts

game.players.localplayer.cameraminzoom = 2 --Now You Have To stay in 3rd person

if it does not work then tell me

5 comments

0

line 66 is a blank line.

0

oh wait nvm

0

dosnt work @sabrna563

0

I updated it now

0

kk

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