How would I rotate the players camera while keeping the players camera on the player?

I want to make the players camera “glitch out” and look in random directions but I’m stuck on how to do so. I tried setting the players camera to scriptable (as others have suggested), but that just paused the players camera in mid air and detached the camera’s subject from the player.

Here is my code:

while player:GetAttribute("Smiling") do
			StatusFrame:SetAttribute("CurrentTime", StatusFrame:GetAttribute("CurrentTime") - 0.1)
			StatusFrame.EffectTime.Text = string.format("%." .. 1 .. "f", StatusFrame:GetAttribute("CurrentTime"))
			
			local intensity = StatusFrame:GetAttribute("CurrentStack") / 10
			
			local rng = math.random(1, 3)
			if rng == 1 then
				camera.CameraType = Enum.CameraType.Scriptable
				camera.CameraSubject = player.Character.HumanoidRootPart
				cameraCFrame = cameraCFrame * CFrame.Angles(0, math.rad(10 * intensity), 0)
			end

			if StatusFrame:GetAttribute("CurrentTime") <= 0 then
				StatusFrame:Destroy()
				player:SetAttribute("Smiling", nil)
				break
			end
			task.wait(0.1)
		end

Setting the subject to the player doesn’t work either.

1 Like

I’m still not entirely sure, but just based off the small snippet of your code the cameraCFrame has some issues.
You are constantly re-assigning the variable to a product of its previous CFrame value with a new random CFrame.Angles.

cameraCFrame = cameraCFrame * CFrame.Angles(0, math.rad(10 * intensity), 0)

I haven’t tested yet, but changing it to your current camera CFrame multiplied with a random angle should fix the issue? (Unless this is purely intentional, as what you’re doing now is probably causing that “detachment issue” you are facing)

cameraCFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(0, math.rad(10 * intensity), 0)
1 Like

Thank you! That does make the rotating work and making the camera type normal again allows it to work! :grin:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.