Need help with Tool following arm

I am working on a fighting game and am adding the ability to “aim” your sword slashes based on where you look. The problem is that the arms will follow the camera just fine but the tools, which I used a Motor6d to attach to the torso, will not follow the arm on their own. I don’t know how to proceed.

image

game:GetService("RunService").RenderStepped:Connect(function()

	local CameraDirection = Root.CFrame:toObjectSpace(camera.CFrame).lookVector
	if Neck and humanoid.Health > 0 then
		if player.Character.Humanoid.RigType == Enum.HumanoidRigType.R6 then

			Neck.C0 = CFNew(0, YOffset, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -asin(CameraDirection.x)) * CFAng(-asin(CameraDirection.y), 0, 0)

			leftArm.C0 = leftArmOrigin
			rightArm.C0 = rightArmOrigin

			if player.Character:FindFirstChildOfClass("Tool") then

				rightArm.C0 = CFNew(1, 0.5, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(-asin(CameraDirection.y), 0, 0) * CFAng(4.7,4.7,9.5)
				leftArm.C0 = CFNew(-1, 0.5, 0) * CFAng(3 * math.pi/2, 0, math.pi)  * CFAng(-asin(CameraDirection.y), 0, 0)* CFAng(7.5,1.5,6.5)

			end
		end
	end
end)

Well, why would the sword follow the arms if it’s welded to the Torso as you said? Shouldn’t it be welded to one of the hands?

1 Like

to add on to what Synteuro said, because it’s welded to the torso, it will only follow the torso. Because the torso doesn’t follow the arms as you have shown in the screenshot, the sword won’t follow the arms.

If you attached it to an arm, doing things like inspect animations would be really hard like throwing the weapon and catching it mid air, etc. Using the arm instead of the torso would fix it, but limit the ability to animate. A better solution would be to manipulate the tool’s Motor6D to the camera, just like the left and right shoulders. I tried to do this and it actually seemed to work, but it was offseted weirdly. I haven’t fully learned 3D math yet, but if any of you all figure it out please reply to me. Thanks!