Arms movement looking quite weird


I have been trying to make the arms of the player attach to the camera. For now I am trying to atleast make them look towards the players mouse. But this issue appears. I have fixed this before but I can’t seem to do it now, as I forgot.

This is the code:

local offset = HRP.Position-Camera.CFrame.Position
	
RightShoulder.C0 = (HRP.CFrame+offset):ToObjectSpace(CFrame.new(HRP.Position+offset,Mouse.Hit.Position))*RightShoulderC0
LeftShoulder.C0 = (HRP.CFrame+offset):ToObjectSpace(CFrame.new(HRP.Position+offset,Mouse.Hit.Position))*LeftShoulderC0

Where HRP is the HumanoidRootPart and LeftShoulderC0 and RightShoulderC0 are the base offset of LeftShoulder and RightShoulder, respectively.

6 Likes

Its been 17 hours… just a bump

1 Like

Could be because you’re just rotating the arms that are attached to the torso instead of making new arms for the view model

1 Like

Or you do have a view model, and if you do have one that has a HRP attach the HRP to the camera so the arms move with it.

1 Like

I do not want a viewmodel. I simply want the players arms to be attached to the camera as said in the post.

I solve my own problems somehow.
Where the offset_2 is the original offset-Vector3.yAxis. Vector3.yAxis is just Vector3.new(0,1,0)


	RightShoulder.C0 = HRP.CFrame:ToObjectSpace(CFrame.new(HRP.Position+Vector3.yAxis,Mouse.Hit.Position))*RightShoulderC0_2
	LeftShoulder.C0 = HRP.CFrame:ToObjectSpace(CFrame.new(HRP.Position+Vector3.yAxis,Mouse.Hit.Position))*LeftShoulderC0_2

Cool!! Could you send the finished product? Id like to see what you were looking for!

Sure but a problem still remains that:

	local offset = HRP.Position-Camera.CFrame.Position
	
	local x,z = offset.X,offset.Z
	
	local RightShoulderC0_2 = RightShoulderC0-Vector3.new(x,1,z)
	local LeftShoulderC0_2 = LeftShoulderC0-Vector3.new(x,1,z)
	
	RightShoulder.C0 = HRP.CFrame:ToObjectSpace(CFrame.new(HRP.Position+Vector3.yAxis,Mouse.Hit.Position))*RightShoulderC0_2
	LeftShoulder.C0 = HRP.CFrame:ToObjectSpace(CFrame.new(HRP.Position+Vector3.yAxis,Mouse.Hit.Position))*LeftShoulderC0_2

As you can see the arms lag behind the camera. So do you have any idea on how to fix it?

Is this handled under RunService.RenderStepped or RunService.Stepped?

Yes, its handled under RenderStepped.
Here is the 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 + (lasty-y)*20)
	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)
	
	local offset = HRP.Position-Camera.CFrame.Position
	
	local x,z = offset.X,offset.Z
	
	local RightShoulderC0_2 = RightShoulderC0-Vector3.new(x,1,z)
	local LeftShoulderC0_2 = LeftShoulderC0-Vector3.new(x,1,z)
	
	RightShoulder.C0 = HRP.CFrame:ToObjectSpace(CFrame.new(HRP.Position+Vector3.yAxis,Mouse.Hit.Position))*RightShoulderC0_2
	LeftShoulder.C0 = HRP.CFrame:ToObjectSpace(CFrame.new(HRP.Position+Vector3.yAxis,Mouse.Hit.Position))*LeftShoulderC0_2

	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.RenderStepped:Connect(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,-80,80)
		CamAngle = Vector2.new(X % 360,Y) * (UIS.MouseDeltaSensitivity)
	end
end)

Try switching to .Stepped instead when it comes to updating the .C0 property?
Basically, under RenderStepped, calculate where it should be, then .Stepped will be used to update the arms.
If none of those works try doing

RunService:BindToRenderStep("update", Enum.RenderPriority.Camera.Value - 1, Update)

Basically, the issue is that I am using :Lerp to smooth out the camera movement. But due to that the arms are sort of lagging forward. I need to put the arms back to where the camera is. Not where the HumanoidRootPart is.

It doesn’t seem that the smoothened camera system cause this, have you tried the solutions I mentioned above?

No, I havent tried the first one as I am confused about what you mean by it.

I can’t really test the code myself, But you can maybe give this a try?

local offset = HRP.Position - Camera.CFrame.Position
local x, y, z = offset.X, offset.Y, offset.Z

local rightShoulderOffset = Camera.CFrame:pointToWorldSpace(Vector3.new(x, 0, z))
local leftShoulderOffset = Camera.CFrame:pointToWorldSpace(Vector3.new(x, 0, -z))

RightShoulder.C0 = RightShoulderC0 * CFrame.new(rightShoulderOffset)
LeftShoulder.C0 = LeftShoulderC0 * CFrame.new(leftShoulderOffset)


It removed my hands.
Also can you help me fixing the weird camera jitter? I don’t know why its doing that.

Oh haha, thats not meant to happen, apologies.
And for the Camera jittering, the only thing i can think of is removing the
* (UIS.MouseDeltaSensitivity) part
So let it be CamAngle = Vector2.new(X % 360,Y). Once again, i can’t test this code at the moment so i’m just doing it by pure guessing. Don’t be surprised if you don’t get correct results :sweat_smile:

Yea, haha no problems. Thanks for the help btw. Ill test it right away!

1 Like

Alright update: The camera jitter did not get fixed.

As expected but it was worth a try. I don’t think i can help you further with the bits of code.
Just because i’m not able to test it myself before sending it off to you, If i can give an answer to something else though, i surely will :+1: