Rotation help please

I’m trying to achieve viewmodel ike view without actually using viewmodels for some reasons
Code:

I haven’t actually manipulated something like this since like an year ago

1 Like

I got it yess
smoooth

local function UpdateHandRotation(dt: number)
	local tool: Tool? = character and character:FindFirstChildOfClass("Tool")

	local torso: BasePart = character:FindFirstChild("Torso")
	if not torso then return end

	local handMotor: Motor6D = torso:FindFirstChild("Right Shoulder")
	if not handMotor then return end

	if tool then
		
		local handle: BasePart? = tool:FindFirstChild("Handle")
		if not handle then return end

		local muzzle: Attachment? = tool:FindFirstChild("MuzzleAttachment", true)

		local mouse: Mouse = player:GetMouse()
		local hitCFrame: CFrame = mouse.Hit
		if not hitCFrame then return end

		local targetPos: Vector3 = hitCFrame.Position
		local at: Vector3 = if muzzle then muzzle.WorldPosition else handle.Position
		local distance: number = (targetPos - at).Magnitude
		local desiredWorld: CFrame = CFrame.lookAt(at, targetPos)
		local desiredRelative: CFrame = torso.CFrame:ToObjectSpace(desiredWorld)
		local rx: number, ry: number, rz: number = desiredRelative:ToOrientation()
		local targetC1_hand: CFrame = CFrame.new(handMotor.C1.Position) * CFrame.Angles(-rx, (distance > 4 and ry or 0) + math.rad(90), -rz)
		local alpha: number = math.clamp(6.7 * dt, 0, 1)
		
		handMotor.C1 = handMotor.C1:Lerp(targetC1_hand, alpha)
	else
	
		handMotor.C1 = CFrame.new(handMotor.C1.Position) * CFrame.Angles(0, math.rad(90), 0)
	end
end

run it every frame increase 6.7 to make it snappier, lower to make it smoother
I will provide a video later

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