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:
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
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
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
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) )