Motor6D Rotation Values Not Setting Properly

I’m trying to make it so players can hold items in my game, so I decided to use Motor6D’s as the attachment method. I used the explorer to edit the values so that the character holds the item “correctly,” and then I apply them in a script when the player picks up an item.

However, the angles 20, -90, 50 turn into 0, -90, 30 once i set them in the script.

Angles set using explorer:

Angles set with the script

Config table:

Offsets = {
			R6 = {
				C0 = CFrame.new(-0.4, -1.4, -0.4) * CFrame.Angles(math.rad(20), math.rad(-90), math.rad(50)),
				C1 = CFrame.new(),
			},
			R15 = {
				C0 = CFrame.new(-0.4, -0.4, -0.4) * CFrame.Angles(math.rad(20), math.rad(-90), math.rad(50)),
				C1 = CFrame.new(),
			},
		},

The script:

local offset = definition.Offsets[rigKey]
local c0, c1 = offset.C0 or CFrame.new(), offset.C1 or CFrame.new()
local motor6D = Instance.new("Motor6D")
motor6D.Part0 = attachPart
motor6D.Part1 = model.PrimaryPart
motor6D.C0    = c0
motor6D.C1    = c1
motor6D.Parent= attachPart

Thanks for any help because I’m really confused.

  • For empty CFrame please use CFrame.identity
    And dont call constructor each time.
  • Consider looking at CFrame overloads and i think
CFrame.new(Vector3.new(),Vector3.new())

Is the one you are looking for.

  • Consider doing better formatting:
--!strict
type Offsets = {
	[Enum.HumanoidRigType]:{
	C0:CFrame;
	C1:CFrame
}
}
local Offsets:Offsets = {
	[Enum.HumanoidRigType.R15]={
		C0=CFrame.identity;--Your cframe thingy here
		C1=CFrame.identity;--Your cframe thingy here
	};
	[Enum.HumanoidRigType.R6]={
		C0=CFrame.identity;--Your cframe thingy here
		C1=CFrame.identity;--Your cframe thingy here
	}
}
1 Like

Thanks for the suggestions on the formatting!
I tried using CFrame.new(Vector3.new(-0.4, -1.4, -0.4), Vector3.new(math.rad(20), math.rad(-90), math.rad(50))) instead of CFrame.new(-0.4, -1.4, -0.4) * CFrame.Angles(math.rad(20), math.rad(-90), math.rad(50)), but unfortunately now my angles appear as -6.6, -150, 0.

1 Like

what is the model.primarypart and attacthPart? if model.primary part is the character primarypart then you may want to change it to humanoidrootpart

1 Like

The model’s primary part is Handle (the mesh used for the model).

okay then the attachpart is the rootpart?

It attaches itself to the Right Arm.

Motor6D.Part0 = character["Right Arm"]
Motor6D.Part1 = Handle

then just try adjusting angles

i will do that as a last resort, but id rather not just guess random angles until it looks right in game

looks like you might need to go ahead with it, since the way youre getting the angle from the explorer isnt giving accurate values when used with the motor.

I ended up discovering the issue. CFrames are rotated in YXZ order. So instead of:

C0 = CFrame.new(x_pos, y_pos, z_pos) * CFrame.Angles(math.rad(x_rot) math.rad(y_rot), math.rad(z_rot))

it would actually be:

C0 = CFrame.new(x_pos, y_pos, z_pos) * CFrame.Angles(0, math.rad(y_rot), 0) * CFrame.Angles(math.rad(x_rot), 0, 0) * CFrame.Angles(0, 0, math.rad(z_rot)),