Weapon Motor6D Arm Rotation

Hey! I’m working on a custom gun system, and I’m trying to get the gun to rotate properly with the arms. However, the gun is welded to the UpperTorso of the character - I’m using Headstackk’s gun animating method, which allows for the gun to be moved freely.

However, the gun doesn’t follow the arms accurately, and the gun is offset from its intended position, which should be in the player’s arms.

Headstackk also seems to have the same issue as me, which you can find below:

Additionally, this post appears to describe the same issue:

Is there any math/offset things I could do to get the gun to be positioned properly with the arms?

Here’s the relevant code that moves the arms & gun:

-- Added code to make the snippet "function"
local Direction = HumanoidRootPart.CFrame:ToObjectSpace(workspace.CurrentCamera.CFrame).LookVector
local AngleX = math.asin(Direction.Y)
local AngleY = math.asin(Direction.X)
--
local AngleOffset = CFrame.Angles(AngleX, AngleY, 0)

Character.Head.Neck.C0 = OriginalNeckC0 * AngleOffset
Character.LeftUpperArm.LeftShoulder.C0 = OriginalLeftShoulderC0 * AngleOffset
Character.RightUpperArm.RightShoulder.C0 = OriginalRightShoulderC0 * AngleOffset
Character.UpperTorso.Tool.C0 = AngleOffset

For reference, OriginalNeckC0, LeftShoulderC0, and RightShoulderC0 are values from the motor6d’s C0 when the player spawns, which is saved to the variables.

Thanks in advance!

1 Like

Hey! Looks like everything you have right now is good, but you might want to look into the C1 property of the tool’s Motor6D and use it alongside your code. From my miniscule understanding of CFrame and Motor6Ds, it acts as an additional offset so you can work toward getting your gun to rotate from a certain axis to keep it aligned with your arms as they all rotate. My first bet is to try and offset the point of rotation to be near the top of the UpperTorso, aligned with your left and right shoulders.

Also, if you didn’t catch this, it’s worth mentioning that if you manage to solve this problem, your arms and gun will still be at an angle as you move your camera up and down. You can already see this with the arms. This occurs because you’re only moving the arms and gun up and down and not side to side, and your upper torso is angled slightly so this causes the deviation as you look up and down. In my latest project I just opted to not animate the torso at all and so this problem didn’t occur, though you may not want to compromise like that. I just didn’t know how to get around it.

Good luck! Although your system looks a lot better than what I can do, I’ll still try to lend a helping hand.

Edit: added clarification

1 Like