Arm rotation and movement help

Hiya, I have been trying to make my players arm which is not a viewport be attached to the camera and behave like a viewport but not itself be a viewport. I don’t want to make a viewport at all so please do not suggest me to.

	RightShoulder.C0 = CFrame.new(((HRP.CFrame*RightShoulderC0):ToObjectSpace(Camera.CFrame)).Position)*RightShoulderC0*CFrame.Angles(0,0,x)
	LeftShoulder.C0 = LeftShoulderC0*CFrame.Angles(0,0,x):Inverse()*CFrame.new(0,-1,0)

With that code I am getting this:

As you see I am using :ToObjectSpace() to get the distance between the arm and the camera and then attempting to attach the arm to the camera. But I am unable to as shown in the video. Currently I am doing it to only the right arm for simplicity sake.

Can anyone please help me figure it out? Thanks!

Full Code
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local RightShoulder = Character:FindFirstChild("Right Shoulder",true)
local LeftShoulder = Character:FindFirstChild("Left Shoulder",true)
local HRP = Character:WaitForChild("HumanoidRootPart")
local Hum = Character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")

local CamAngle = Vector2.new(0,0)
local RightShoulderC0:CFrame = RightShoulder.C0
local LeftShoulderC0:CFrame = LeftShoulder.C0

local function lerp(a,b,t)
	return a + (b - a) * t
end

Hum.AutoRotate = false
local lasty = 0
local function Update(dt)
	Camera.CameraType = Enum.CameraType.Scriptable
	UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
	UIS.MouseIconEnabled = false
	local whitelist = {"Left Arm","Right Arm"}
	for i,v in pairs(Character:GetChildren()) do
		if v:IsA("Accessory") then
			local p = v:FindFirstChild("Handle")
			if p then
				p.LocalTransparencyModifier = 1
			end
		end
		if not table.find(whitelist,v.Name) and v:IsA("BasePart") then
			v.LocalTransparencyModifier = 1
		end
	end

	local HeadCF = Head.CFrame
	local HeadPCF = CFrame.new(Head.Position)

	local RotX = CFrame.Angles(0,math.rad(CamAngle.X),0)
	local RotY = CFrame.Angles(math.rad(CamAngle.Y),0,0)
	local AngleCF = HeadPCF*RotX*RotY
	local DirectionalCF = CFrame.new(AngleCF.Position,AngleCF:ToWorldSpace(CFrame.new(0,0,-1)).Position)
	local x,y,_ = DirectionalCF:ToOrientation()
	local HumDirection = HRP.CFrame:VectorToObjectSpace(HRP.Velocity)/16
	local z = math.rad(HumDirection.X*2.5 + math.clamp((lasty-y)*20,-3,3))
	local ZRot = CFrame.Angles(0,0,-math.clamp(z,-10,10)):Inverse()
	lasty = y
	local XYRot = CFrame.Angles(-x-math.rad(HumDirection.Z*2.5),-y,0):Inverse()
	
	local FinalCF = HeadPCF*XYRot*ZRot
	Camera.CFrame = Camera.CFrame:Lerp(FinalCF,dt*15)


	-- Help me part.


	RightShoulder.C0 = CFrame.new(((HRP.CFrame*RightShoulderC0):ToObjectSpace(Camera.CFrame)).Position)*RightShoulderC0*CFrame.Angles(0,0,x)
	LeftShoulder.C0 = LeftShoulderC0*CFrame.Angles(0,0,x):Inverse()*CFrame.new(0,-1,0)


	-- Help me part.


	Camera.FieldOfView = lerp(Camera.FieldOfView,70 + (HRP.Velocity.Magnitude/16) * 5,dt*7.5)

	local hrpx,hrpy,hrpz = HRP.CFrame:ToOrientation()
	HRP.CFrame = CFrame.new(HRP.Position)*CFrame.Angles(hrpx,y,hrpz)
	if UIS:IsKeyDown(Enum.KeyCode.LeftAlt) then
		UIS.MouseBehavior = Enum.MouseBehavior.Default
		UIS.MouseIconEnabled = true
	end
end

RS:BindToRenderStep("UpdateCamera", Enum.RenderPriority.Camera.Value - 1, Update)

UIS.InputChanged:Connect(function(Input,GPE)
	if Input.UserInputType == Enum.UserInputType.MouseMovement then
		local Delta = UIS:GetMouseDelta()
		local X = CamAngle.X - math.clamp(Delta.X/6,-10,10)
		local Y = math.clamp(CamAngle.Y - Delta.Y/4,-89,89)
		CamAngle = Vector2.new(X % 360,Y) * (UIS.MouseDeltaSensitivity)
	end
end)
1 Like

Make that Camera.CFrame and apply an offset to it. In the ToObjectSpace, use the torso part.

2 Likes

Sorry for late reply.

Like this?

	RightShoulder.C0 = CFrame.new(((Camera.CFrame*RightShoulderC0):ToObjectSpace(HRP.CFrame)).Position)*RightShoulderC0*CFrame.Angles(0,0,x)
	LeftShoulder.C0 = LeftShoulderC0*CFrame.Angles(0,0,x):Inverse()*CFrame.new(0,-1,0)


Because… well…

And with this

	RightShoulder.C0 = CFrame.new(((Camera.CFrame):ToObjectSpace(HRP.CFrame)).Position)*RightShoulderC0*CFrame.Angles(0,0,x)
	LeftShoulder.C0 = LeftShoulderC0*CFrame.Angles(0,0,x):Inverse()*CFrame.new(0,-1,0)

1 Like

Hm, maybe try offsetting it because I think the C1 is interfering.

What do you mean offsetting it?

You can also set it to CFrame.identity to remove it. Just set the C1.

Setting the C1 does not give me what I want. Doing that causes the hand to rotate weirdly during the animation.

You’re supposed to set it to CFrame.identity once to remove the offset. There should not be any effect on animations since they override all CFrame properties.

So your saying set the C1 to CFrame.identity?

Yes, but you might have to adjust C0 to compensate.

Alright ill let you know when it works or doesn’t. Thanks for the support!