‘targetOrientation’ is the default bone orientation + an offset. I have it working where this offset is applied to the local left/right direction of the bone (z-axis). However, this causes the rig to go up/down realtive to the rootpart when turning. This is due to the bone axis not being perfectly aligned with the rootpart’s axis.
Is there a way to add an offset to the bone’s orientation that is relative to the rootpart; not relative to the bone?
Here are images for illustration:
I want to rotate the blue part along the y-axis of the red part. Only using the ‘Orientation’ property on the blue part! In this case the axis of the red part is the same as the world root, but that changes if the red part rotates.
I have it almost working now.
It works only if my model’s rootpart is aligned with the world root on startup. I want it to work in whatever orientation the rootpart is. Here’s part of the code:
local defaultCFrame = bone.WorldCFrame
local function getWorldOrientation(bone, offset)
local rotBase = rootPart.CFrame * CFrame.Angles(0, math.rad(offset), 0)
local newRotationWorldSpace = rotBase * defaultCFrame.Rotation
local test = bone.Parent.WorldCFrame:Inverse()
local destCFrame = (test*newRotationWorldSpace).Rotation + bone.CFrame.Position
local rx, ry, rz = destCFrame:ToOrientation()
local dx, dy, dz = math.deg(rx), math.deg(ry), math.deg(rz)
return Vector3.new(dx, dy, dz)
end
-- Rotate 'bone' with 45° along the rootpart's y-axis
bone.Orientation = getWorldOrientation(bone, 45)
I think I have to use a different reference CFrame instead of bone.WorldCFrame. I can’t figure out what though…
Any help is greatly appreciated .
local defaultCFrame = rootPart.CFrame:Inverse() * bone.WorldCFrame
local function getWorldOrientation(bone, offset)
local rotBase = rootPart.CFrame * CFrame.Angles(0, math.rad(offset), 0)
local newRotationWorldSpace = (rotBase * defaultCFrame).Rotation
-- Convert from world space to local bone space
local test = bone.Parent.WorldCFrame:Inverse()
local destCFrame = (test*newRotationWorldSpace).Rotation + bone.CFrame.Position
local rx, ry, rz = destCFrame:ToOrientation()
local dx, dy, dz = math.deg(rx), math.deg(ry), math.deg(rz)
return Vector3.new(dx, dy, dz)
end
bone.Orientation = getWorldOrientation(bone, 45)