How to make camera rotate left or right when player moves left or right

For the 2 days I have been attempting to find a way to rotate a camera left or right when a player moves left or right, however I couldn’t find anything about it and camera manipulation isn’t really my thing.

So if anyone can help me, or link me a topic that will solve my issue then that would be appreciated.

12 Likes

Hi, do you mean as a shake effect for the walking of the player?

2 Likes

No, when the player moves left the camera will tilt left, when the player moves right the camera will tilt right.

1 Like

The player’s camera (the camera should do this by default)? Or just a part in the workspace?

1 Like

Im not quite sure how to explain this properly so hopefully this image helps you understand what i want to achieve

1 Like

Yes I understand that, but what do you mean by camera? A part, or the player’s camera?

1 Like

The players camera the one they control.

1 Like

Look in this and see if it helps How do I tilt the camera?

1 Like

I understand cframe, I just don’t know how to get the way the players moving, then rotate the camera according to that.

1 Like

Roblox automatically rotates the player’s camera when they turn. Are you changing the camera type to Enum.CameraType.Scriptable?

1 Like

Its not that. its when the player moves left I want the camera to tilt left the camera is working fine when the player looks around it just want it so when the player moves left it will tilt left

1 Like

Can’t you just check for UserInputService:IsKeyDown(Enum.KeyCode.(A or D)), times the CFrame and revert to normal when neither is down?

1 Like

I’ve tried that, but you cant apply any changes to the camera without it being scriptable but i still want the camera to have the same position

1 Like

why you should do is
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

1 Like

Then from there do UIS to get when the player does a or d then you know how to tilt the cam.

1 Like

Can you stick two parts on either side of the player somehow and do a while loop to make the camera CFrame in the parts depending on which key is pressed? That way if the player moves the part follows so the camera should update its position similarly to Enum.CameraType.Custom

1 Like

Those parts would add difficulties in themselves, and if the player dies then you need to think about stuff like that.

1 Like

He wants to have the camera follow the player so Enum.CameraType.Scriptable by default would leave the camera stuck.

2 Likes

In some cases it does, but this is just a glitch

1 Like

I got it working, im gonna add some cframe lerping but other than that it works fine scorpions idea to use parts helped because that helped me figure out the rotation, but thanks everyone that responded.
if your want the code here it is:

local camera = workspace.Camera

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:wait()

local runService = game:GetService("RunService")

runService.RenderStepped:connect(function()
	local humanoid = char:FindFirstChild("Humanoid")

	if humanoid then
		local a = false
		local x,y,z = camera.CFrame:ToEulerAnglesXYZ()
		if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.A) then
			a = true
			camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(2))
		end
		if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.D) then
			a = true
			camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(-2))
		end
		if a == false then
			camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x,y,z)
		end
	end
end)
9 Likes