Add CFrame using Object Space

Hello!

I’m currently making a game that allows you to chop a tree in sections (Similar to Lumber Tycoon 2’s system). It’s going great, but I’ve run into a small problem.

When I create two halves, I do math using the y axis to reposition them. Here’s the code:

((originalObject.Size / 2) + originalObject.Position.Y)

(For the top half ^)

((originalObject.Size / 2) - originalObject.Position.Y)

(For the bottom half ^)

This works wonderfully until I get into other directions. If the log is lying sideways on the ground they will stack on top of each other as the Y direction is in world space.

How would I go about changing this to add in object space? I’ve experimented with CFrame:ToObjectSpace() But I can’t wrap my head around the math of that.

Thanks!

I believe what you actually want is VectorToWorldSpace.

If you want to offset a part x by some given vector y relative a part z, you’d do this:
x.CFrame = z.CFrame + z.CFrame:VectorToWorldSpace(y)

Gives you this effect (it also keeps orientation):

2 Likes

That’s exactly what I was looking for, thanks!