How do I pivot the player's shoulders around their character's torso using Motor6D?

Hi,

I’m attempting to pivot my character’s shoulders around my character’s torso along the x-axis using the Left & Right Shoulder Motor6Ds. I want the shoulders to be the same distance to each other no matter what rotation, rather than the traditional methods I’ve seen before that involve making wonky arm directions. The linked GIF should demonstrate what I mean:
Example of what I want to achieve (GIF)

The reason why I want this specific look is because characters in my game lean towards the direction they walk in. This can look nice until you equip a two-handed weapon, or really any weapon that is direction-based (like a gun).
Walking around with a gun equipped (GIF)Walking around with nothing equipped (GIF)
As you can see in the GIFs, the gun doesn’t point where the player is looking, which will look especially weird when you move and shoot at the same time. I’ve tried writing code that would counteract this offset but they all result in either odd looking arm positions or just being entirely glitched out.

I’ve tried to make up both C0 and C1 changes in my scripts but none of them yield results even close to what I want to achieve. I then tried searching the devforums but it only showed questions like this (“How to make the character rotate with the cursor?”) and this (“How to make arms rotate with mouse?”) which don’t really apply to my situation.

I know this is more CFrame and math related but even when I attempt to figure out the math, I have a hard time successfully applying it into my code. Even someone explaining the math / CFrame logic behind producing is very much appreciated.

I did make a post about this topic before but it never really gained traction and I didn’t describe it in a way that made more sense, I hope this one makes more sense to the people reading it. If something I wrote doesn’t make sense, please tell me.

i was doing the same thing for bows recently

you can edit the c1 of the motor6ds that control the arm cframes (located in torso)

they are relative to the torso cframe, so you have to set them to

Torso.CFrame:Inverse() * cframe -- cancels torso cframe with :Inverse() and then adds cframe

where cframe is your own cframe relative to global space, something like

local cframe = CFrame.new(math.cos(rotation), 0, math.sin(rotation)) * CFrame.Angles(0, rotation, 0)
--tweak this, is probably off
1 Like

I’ll go ahead and implement this and come back with the results.

Is this how I was supposed to use this code? I’m getting strange results which can fling my character away

My code looks like this:

local angleOffset = math.rad(45) -- set to a constant for testing purposes
local cframe = CFrame.new(math.cos(angleOffset), 0.5, math.sin(angleOffset)) * CFrame.Angles(0, angleOffset, 0)
motors["Right Shoulder"].C1 = torso.CFrame:Inverse() * cframe