How would I go about pointing a players arm towards a part? More specifically, I am unsure how to go about manipulating the players’ shoulders’ Motor6D.C0 property to point towards a part each RenderStepped while using the shoulders natural position.
I have this code so far, which works, but the shoulder remains at the midpoint of the arm (Part0):
local shoulder: Motor6D = character["LeftUpperArm"]["LeftShoulder"];
local jointPosition = shoulder.Part0.CFrame:toWorldSpace(CFrame.new(0,0,0))
local cframe = CFrame.new(jointPosition.p, workspace.PartToPointAt.Position) * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new(0, -1, 0)
shoulder.C0 = shoulder.Part0.CFrame:toObjectSpace(cframe)
I cannot use pre-defined offsets, as the R15 rigs scale during gameplay.
This creates a CFrame that is angled to face the LookAtPart.
But, it aligns it with the front. If improper alignment occurs, you can use a CFrame.Angles():
lookAtCFrame = lookAtCFrame * CFrame.Angles(0, math.rad(90), 0)
--using math.rad(90) for an example
This does not work. The arm has moved to a fixed position, and is not pointing at the part. Player movement does not effect the arm. The result is exactly the same if I replace CFrame.new with CFrame.lookAt.