Tween CFrame of bone relative to parent part

I want to tween the rotation of a bone. I’m using the following line to tween the bone:

TweenService:Create(bone, TweenInfo.new(0.75), { Orientation = targetOrientation }):Play()

‘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:
image
image
image
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.

Thanks for your help

1 Like

Bump.
I always found CFrames difficult to use, so I need all the help I can get :slight_smile: .

1 Like

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 :slight_smile: .

bump.

20 characters

Working code (external help was needed):

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)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.