Bone.Transform to WorldCFrame

Hi

I want to use bone.Transform to move the bone towards a CFrame location in world space.
Attached is a file that correctly does this for a non-nested bone hierarchy:
bone_transform_test.rbxl (54.1 KB)


This uses the following code:

local part = workspace.Part
local attachment = part:FindFirstChildOfClass("Bone")
local targetPart = workspace.TargetPart

local attachmentWorldCFrame = attachment.WorldCFrame
local targetWorldCFrame = targetPart.CFrame

local relativeCFrame = attachment.Parent.CFrame:inverse() * targetWorldCFrame

attachment.Transform = relativeCFrame

However, this breaks for a nested bone hierarchy. I assume that is due to multiple offsets being inherited from parents while the code only accounts for the direct parent offset.
This is the result I get (see the rbxl file):

TLDR: I want to replace bone.WorldCFrame = targetCFrame to bone.Transform = ... so that the bone ends up at ‘targetCFrame’ (same result for both calls).

Thanks for your help.

As usual with CFrames it’s a small mistake that leads to completely wrong results.
Here’s the correct relative CFrame to be applied (directly on bone rather than on it’s parent):

local relativeCFrame = bone.WorldCFrame:Inverse() * targetWorldCFrame

and the fixed placefile: bone_transform_test.rbxl (54.1 KB)

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