How would i go on about making my Arms Follow the Camera/Torso?

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!
    like the title says, i want the Arms follow my camera.

  2. What is the issue? Include screenshots / videos if possible!
    issue is, i have no idea how. i already tried and all it did was fling me around the map, being armless, or sometimes not even having a torso. so i just reverted everything back to my original working script. which only affects the head and the Uppertorso.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    already tried, and none of them worked, or is not supported to my version, this had me gotten so angry i even tried using gpt4, which didnt even work.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer

local function setupCamera()
	local character = player.Character or player.CharacterAdded:Wait()
	local root = character:WaitForChild("HumanoidRootPart")
	local neck = root.Parent.Head:WaitForChild("Neck", true)
	local waist = root.Parent.UpperTorso:WaitForChild("Waist", true)
	local yOffsetNeck = neck.C0.Y
	local yOffsetWaist = waist.C0.Y
	local Crouch = player:WaitForChild("Crouch")
	local OnPhone = player:WaitForChild("OnPhone")

	local CFNew, CFAng, asin, clamp = CFrame.new, CFrame.Angles, math.asin, math.clamp

	local function clampAngles(x, y)
		local maxXAngle = math.rad(45)
		local maxYAngle = math.rad(45)

		x = clamp(x, -maxXAngle, maxXAngle)
		y = clamp(y, -maxYAngle, maxYAngle)

		return x, y
	end


	local function onRenderStepped()
		local cameraDirection = root.CFrame:toObjectSpace(camera.CFrame).lookVector

		if neck then
			local x, y = -asin(cameraDirection.x), asin(cameraDirection.y)
			x, y = clampAngles(x, y)
			neck.C0 = CFNew(0, yOffsetNeck, 0) * CFAng(0, x, 0) * CFAng(y, 0, 0)
		end

		if waist then
			local x, y = -asin(cameraDirection.x), asin(cameraDirection.y)
			x, y = clampAngles(x, y)

			if Crouch.Value or OnPhone.Value then
				waist.C0 = CFNew(0,0,0) * CFAng(0,0,0) * CFAng(0,0,0)
			else
				waist.C0 = CFNew(0, yOffsetWaist, 0) * CFAng(0, x, 0) * CFAng(y, 0, 0)
			end		
		end
	end

	return onRenderStepped
end

local function onCharacterAdded(character)
	local onRenderStepped = setupCamera()

	game:GetService("RunService").RenderStepped:Connect(onRenderStepped)
end

player.CharacterAdded:Connect(onCharacterAdded)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

3 Likes

I’ve done this already using an IKControl. It’s really simple. You just create the IKControl, set its EndEffector to the head and the ChainRoot to UpperTorso, set the type to LookAt, and then you can simply use a small part that you position in front of the camera and the character will automatically look at it.

3 Likes

i have not learned IKcontrols yet. but the documentation gives me a good idea. ill give it a go but would that mean ill have to replace my old script?

Ye obviously you’ll have to disable the old script. Keep it commented and see if you can make it work through a IKControl

Okay, i have no idea how to do this. Well kind of. Problem is how would i make a part follow the camera for this to work? I mean like, for the IKcontroller to lookat the part that is connected to the camera, that part also has to be facing the camera

No it doesn’t have to face the camera, as IKControl doesn’t use the CFrame but only the position. I’ve done it this way:

-- In your client script
local lookPart = Instance.new("Part");
lookPart.Size = Vector3.new(.1, .1, .1);
lookPart.Transparency = 1;
lookPart.CanCollide = false;
lookPart.Anchored = true;
lookPart.Parent = workspace;

-- create the ikcontrol and set every property, I won't write all of them
IKControl.Type = Enum.IKControlType.LookAt;
IKControl.Target = lookPart;
IKControl.EndEffector = character.Head;
IKControl.ChainRoot = character.UpperTorso;

RunService.PreRender:Connect(function()
   -- so the part is constantly in front of the camera
   lookPart.Position = (camera.CFrame * CFrame.new(0, 0, -75)).Position;
end);

oh, that is not what i expected i thought i was supposed to weld it to the camera. ah. anyways, now i get it. okay okay okay im gonna rewrite and modify the code and see if i could get my own version of this to work. ill make your reply solution if it works. I greatly appreciate you helping me!

Edit: IT WORKS! YES! FINALLY! THANK YOU THANK YOU THANK YOU! my god 4 hours of trying to fix my old code and all i could have done was use an ikcontroller! again thank you so much for helping me!

No worries, IKControls are really useful and simplify something that would take a long time to code. Glad I could help

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