Arms follow the Mouse in a.. weird way

So basically, I set up a script where the arms follow the mouse in the Y-scale (using the shoulder motor6Ds), but I cannot seem to move the arms properly facing the mouse.

This was my closest attempt to doing so, but I noticed a bit of a problem; the arms are facing the mouse in the wrong angle, and only align when I move the mouse to the front or the back of the character.

https://gyazo.com/02952a558a916f9f5ce684a8878b7540

This is the code that I use to move the arms (ran every frame when the character currently has an equipped tool) :

RightShoulder.C0 = RightShoulder.C0:lerp((Character.Head.CFrame * CFrame.new(1, -1, 0)):toObjectSpace(CFrame.new(Vector3.new(HRP.Position.X, HRP.Position.Y, HRP.Position.Z), Vector3.new(playerMouse.Hit.p.X, HRP.Position.Y, playerMouse.Hit.p.Z))):inverse() * CFrame.Angles(0, math.pi/2, 0), 1/2)

LeftShoulder.C0 = LeftShoulder.C0:lerp((Character.Head.CFrame * CFrame.new(-1, -1, 0)):toObjectSpace(CFrame.new(Vector3.new(HRP.Position.X, HRP.Position.Y, HRP.Position.Z), Vector3.new(playerMouse.Hit.p.X, HRP.Position.Y, playerMouse.Hit.p.Z))):inverse() * CFrame.Angles(0, -math.pi/2, 0), 1/2)

I have tried multiplying the CFrame, wrapped in toObjectSpace(), with a CFrame.Angles, but that only seems to move where they properly align.

If anyone could help with my issue, that would be appreciated!

(also if this confuses you a bit, I’m sorry. I tried my best to explain)

1 Like

It looks like the inverse rotation of the mouse. You should be able to simply throw in a negative multiplier into the CFrame equation to fix the issue.

The easiest way to do this is to actually use something called fake arms, where the real arms of the player is hidden and the fake arms are shown. This is because the fake arms are not connected to the body of the player, and can be manipulated in global space, instead of trying to work with weld offsets. Otherwise, you need to figure out the location of the pivot in world space (part0CF * C0 or part1CF * C1) and then create a new offset by using this pivot.

1 Like

Inversing any value of the CFrame throws the arm off, apparently.

1 Like

Well assume that the root part is the torso and the arms are limbs.
The pivot (based on the root part) (if Part1 is the torso!)
pivotCF = part1.CFrame * joint.C1
This is the world cframe of the pivot holding these two together.
When you change C0 or C1, you are changing the location of this pivot, relative to each part.
part0.CFrame for example, would be the same as part1.CFrame * joint.C1 * joint.C0:inverse()
(this comes from part1.CFrame * joint.C1 = part0.CFrame * joint.C0)
So in this case, you are trying to find for what C0 does the part offset from the pivot in the right way. This again, involves way more complex thinking than with just fake arms. A simple solution would be potentially to just store the C0 and tack it on after your rotation, but this doesn’t always work.

I’m not sure if this will work for what I intend to have. (Unless if I misunderstood a whole lot your explanation about joint CFrames), is there any other solution that may possibly work with this?

To make my problem possibly easier to understand, is there a way to move the arms in favour of the mouse direction and not the opposite (goes counterclockwise instead of clockwise)?

https://gyazo.com/d6294005020b1bdb28d699f0bcfb3e42

Apologies if I sound a bit arrogant, also. I’ve been stuck for days trying to fix it.

My explanation/description is to show you how joints work. You have to figure out how to make them work in your case if you want the orientation to be accurate. Aside from that, I still highly recommend using fake arms as it is 10000x easier… especially since you are literally only dealing with like R6 arms. This method works for any other kinds of rigs too.

1 Like