Applying part rotation to player camera

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve camera movement by copying a part’s rotation (CameraBone inside the viewmodel for the gun).
    The animation moves the CameraBone, all I want to do is rotate the camera while the player still has control over the camera

  2. What is the issue? Include screenshots / videos if possible!
    When copying the CameraBone’s rotation to the camera it completely bugs out, the player camera goes crazy, amplifying the rotation and not returning to original position.
    Here is a video for demonstration

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I did, many posts listed the same answer, which I used before but that the camera go crazy.

This is what I used for the rotation

	runService.RenderStepped:Connect(function()
		
		if camera:FindFirstChild(weaponInSlot.."_Viewmodel") then	
			
			local cameraBone = camera:FindFirstChild(weaponInSlot.."_Viewmodel").CameraBone
			
			local X, Y, Z = cameraBone.CFrame:ToEulerAngles()
			local cameraPos =  CFrame.new(camera.CFrame.Position)
			camera.CFrame = cameraPos * CFrame.fromEulerAnglesXYZ(X,Y,Z)
			
			camera:FindFirstChild(weaponInSlot.."_Viewmodel").HumanoidRootPart.CFrame = camera.CFrame * CFrame.new(0, 0, 0.6)		
				
		end
		
	end)
1 Like

Instead of using just .RenderStepped, try :BindToRenderStep() instead and set the priority to Enum.RenderPriority.Camera

1 Like

Thanks for the reply, appreciate it!

I tried what you suggested, and sadly nothing has changed, it still is locked in place and the camera still gets bugged like in the video.

I am not entirely sure, but assuming you’re using roblox’s character controller, I think the character control scripts rely on camera CFrame to properly control the character, so in theory by updating the rotation you’re messing with the character’s ability to be controlled. I hope I’m wrong, but you might have to fork the control module and make some edits to achieve what you want.

Alternatively, I wrote this up real quick. My idea with this is to have the control modules calculate player movement based off the real camera cframe, whilst changing the camera cframe just right after that script runs to render the rotated camera cframe instead if that makes sense. I have no idea if this will work, but I think its worth a quick shot. Let me know how it goes

local oldCFrame
local runservice = game:GetService("RunService")

runservice:BindToRenderStep("cameraThing", Enum.RenderPriority.Camera.Value+1, function()
	oldCFrame = workspace.CurrentCamera.CFrame
	-- Add your camera cframe updating code here!
end)

runservice.Stepped:Connect(function()
	if oldCFrame then workspace.CurrentCamera.CFrame = oldCFrame end
end)
1 Like

Hey, thanks again. I tried what you sent and sadly it didn’t work either.

I’m gonna put this camera movement thing aside, I’ll pick it back up when I have more experience with this kind of stuff.

I really appreciate your help, thank you for that.