Accessory Attachment CFrame Rotation

I’m trying to make a system to create custom items using current catalog meshes and textures. The problem is some of these meshes are not correctly sized, rotated, and positioned and need to be adjusted. I’ve got size and movement working, even rotation if i don’t move it first, but I’m having an issue with rotation when combined with movement. I can only get the part to rotate around the attachment worldspace point like this:

2018-10-07_21-44-41

I’m wanting it to rotate around its own axis. I’ve been trying to figure out CFrames but they are not my specialty by far. Here is what I currently have for the code:

RotateHandles.MouseDrag:connect(function(axis, relativeAngle, deltaRadius)
	local ax, ay, az 
    ax = axis==Enum.Axis.X and relativeAngle - lastAngle or 0
    ay = axis==Enum.Axis.Y and relativeAngle - lastAngle or 0
    az = axis==Enum.Axis.Z and relativeAngle - lastAngle or 0
	
	AccessoryAttachment.CFrame = AccessoryAttachment.CFrame * CFrame.Angles(-ax, -ay, -az)
	
    lastAngle = relativeAngle
end)

I dont get what this is supposed to be used for. If you want to rotate something just use current*CFrame.Angles(x,y,z) where x y and z are changes in rotation. Also this will rotate the attachment so if you move the attachment, the attachment will stay in the same place but the accessory will move so it will still rotate from the neck. This can be demonstrated by moving it around in studio on a rig. The cframe of the accessory should be at rigpartCFrame*rigAttachCFrame*attachCFrame:inverse() with attachCFrame’s world coordinate always being rigpartCFrame*rigAttachCFrame.
Knowing this, you could try to rotate the accessory handle itself instead and calculate the offset the attachment would need. Example:

local currentWorld = handleCFrame
local wantedWorld = handleCFrame * myrotation
attachCFrame = currentWorld:toObjectSpace(wantedWorld*attachCFrame)
6 Likes

Wow, thank you! That works perfectly. I had to apply the same concept to my move code but it works exactly how I want it to now.

As far as its purpose, it’s along the lines of RBXleaks :grimacing:
I used to make them myself but it got too old, this way the players can make it themselves.