Get Bone World CFrame

Have you ever for some reason wanted to calculate the world position of a bone ?
Here’s is how it’s done.

local function getWorldPosition(bone)
	local current = bone
	local worldCFrame = bone.CFrame
	--local transformation=bone.CFrame
	local boneoffset=bone.CFrame
	while current.Parent and current.Parent:IsA("Bone") do
		current = current.Parent
		worldCFrame = current.CFrame * worldCFrame	
	end
	boneoffset=worldCFrame
	if current.Parent:IsA("BasePart") then
		worldCFrame = current.CFrame * worldCFrame
		worldCFrame = current.Parent.CFrame * worldCFrame
	end
	--local change=worldCFrame
	return worldCFrame.Position,boneoffset
end

Why is this useful? for realtime calculation of bones world cframes so you can place an object on the bone such as a flamethrower. It’s actually quite similar to what you would use a rigid constraint for.

To visualize what it is doing think of how a bones properties are of a cframe offset from its parent. it repeatedly checks if the parent is a bone as it continues the loop, when its not the accumulated cframe is summed to the cframe of the initial part. It matches the property of WorldCFrame that is unreadable during runtime but visible in studio.
image

If anyone has any questions feel free to ask.

Is this usable with animations? I think it is, but I haven’t tested it, it’s a game changer if it does. :slight_smile:

2 Likes

Can’t you just use CFrame:ToWorldSpace() for this?

Or just… Bone.WorldCFrame lol

4 Likes

Huh well I see that’s kind of funny. making code that is already native feature. That’s how you know it’s a good idea. :slight_smile: Last time I had that happen I published this Resize Model Scale X,Y,Z Tween Emitters, Bones, Mesh, Motors, HipHeight, Lights,Tool.Grip, Textures, Fire, Smoke,Weld [Open Source] - #10 by Magus_ArtStudios

useful or not, if it wasn’t for this post I would not have discovered Bone.WorldCFrame, so still a W

1 Like

Yeah I definitely want to do some experimentation with that property and see what it can do! It seems almost too easy. At the very least if someone where to have a pipeline they could test both methods for performance. Although, I’d imagine the native implementation is more performant.