How do I make this C0 relative to HumanoidRootPart?

I’m trying to make the character’s arm follow where the mouse points, but it’s relative to the HumanoidRootPart instead of Torso, while not creating any new Motors (Only using Left and Right Shoulder on a R6 character)
Here’s a GIF explaining what’s happening:
https://gyazo.com/64f8df17387a17c927a38f719c536710

The red part is the HumanoidRootPart, and I have a code that moves the C0 to where the mouse is pointing at:

				char.Torso["Right Shoulder"].C0 = CFnew(1,0.5,0) * CFAngles(-math.asin((mouse.Origin.p - mouse.Hit.p).unit.y),1.55,0)
				char.Torso["Left Shoulder"].C0 = CFnew(-1,0.5,0) * CFAngles(-math.asin((mouse.Origin.p - mouse.Hit.p).unit.y),-1.55,0)

From the GIF, you can see when I point frontwards, the arms are pointing at the floor because the torso is tilting downwards too. So I want to use the HumanoidRootPart, which is not tilted by the animation to calculate this angle instead, is it possible? I think something have to be changed at CFnew(1,0.5,0) ?

Blue: Torso and Right Arm
Black: Root Part and where I want the arm to be at

2 Likes

Not sure, but try using:-

(root.CFrame:ToObjectSpace(mouse.Hit).p - root.CFrame.p).Unit

(where root is the HumanoidRootPart)

instead of (mouse.Origin.p - mouse.Hit.p).unit

1 Like

It’s a bit quirky now, but still follows torso’s orientation when it’s tilted:
https://gyazo.com/9f9d3b34498c01684507a0e6d64a5e7c

1 Like

You can retrieve the relative CFrame from torso to pointer location like so
local relative = torso.CFrame:Inverse() * mouse.Hit.p

Then solve the angle of it with math.atan2(-relative.Z, -relative.Y)

Testing script
local char = script.Parent
local torso = char:WaitForChild("UpperTorso")
local mouse = game.Players.LocalPlayer:GetMouse()
local shoulder = char:WaitForChild("RightUpperArm"):WaitForChild("RightShoulder")
local oc = shoulder.C0

while wait() do
	local relative = torso.CFrame:Inverse() * mouse.Hit.p
	shoulder.C0 = oc * CFrame.Angles(math.atan2(-relative.Z, -relative.Y),0,0)
end

2 Likes

Still got the similar quirky results, I think sticking with the original code -math.asin((mouse.Origin.p - mouse.Hit.p).unit.y) and try to modify (like add/subtract?) the result might work.

I created a Motor6D connected from HMR and a test part, the test part is exactly what I want the arm to be at, while it’s not connected to HMR but the torso.
https://gyazo.com/fa102db42206c55f9c59e15a3a61c167

Is it possible?..

2 Likes

Well, what if you just try to shift the arms a bit upwards?

There is a slight angular displacement between the LookVectors of the rootpart and the torso
You can calculate the shift using dot product…

Red: Torso
Black: HumanoidRootPart
Blue: Mouse

So for the angle…

x = math.acos(root.CFrame.LookVector:Dot(torso.CFrame.LookVector))

then just add or subtract that with -math.asin((mouse.Origin.p - mouse.Hit.p).unit.y) (whatever suits your case…)

Again, not sure it would work in your case but just an idea.

3 Likes

Sometimes it returned nan, and for some reasons it only works for Right Arm…

For the left hand, does that work in the opposite sense, in an unexpected way or it does not work?

Nevermind, my bad, I did the addition in the wrong place.
However, why it returns nan sometimes? The character go invisible when it returns nan.
https://gyazo.com/9d44e3ee89d459058b028c4119fb2eb3

Edit: Found a quick solution, thanks for your help!

1 Like

I’m trying to do the same for Z axis too, and I used ToObjectSpace.

x,y,z = char.Torso.CFrame:ToObjectSpace(char.HumanoidRootPart.CFrame):ToEulerAnglesXYZ()

Left Shoulder C0 = Left Shoulder C0 *
CFAngles(XVector + x , -1.55 + y, z), where XVector is the mouse unit
( -math.asin((mouse.Origin.p - mouse.Hit.p).unit.y) )

Right arm works as intended, however the left arm seems to be at the wrong position, any possible solutions?
https://gyazo.com/e915f34a3d4639b880736cfec563ec0c