ne3ulimity
(ne3ulimity)
April 21, 2025, 11:16pm
#1
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
b6d7a
(b6d7a)
April 22, 2025, 9:20pm
#4
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).
b6d7a
(b6d7a)
April 22, 2025, 9:50pm
#6
okay then the attachpart is the rootpart?
ne3ulimity
(ne3ulimity)
April 22, 2025, 10:55pm
#7
It attaches itself to the Right Arm.
Motor6D.Part0 = character["Right Arm"]
Motor6D.Part1 = Handle
b6d7a
(b6d7a)
April 22, 2025, 11:08pm
#8
then just try adjusting angles
ne3ulimity
(ne3ulimity)
April 22, 2025, 11:11pm
#9
i will do that as a last resort, but id rather not just guess random angles until it looks right in game
b6d7a
(b6d7a)
April 22, 2025, 11:23pm
#10
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.
ne3ulimity
(ne3ulimity)
April 22, 2025, 11:27pm
#11
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)),