CFrame problem regarding repositioning to the correct direction regardless of rotation/orientation?

Hello, I’m trying to make a door script and I am horrible at CFrames.
Currently, my tweeninfo is this:

local function doorTweenFinish(part)
	local goal = {
		Size = Vector3.new(part.Size.X, part.Size.Y * 0, part.Size.Y),
		CFrame = part.CFrame - Vector3.new(part.Size.Y / 2, 0, 0)
	}
	return goal
end

I adjust the position because, without it, it would be resizing on both sides instead of only on one side.

This is what I’m trying to accomplish:

Here is what I have right now:

What’s going on is that it’s resizing it on one side as intended, but the rotation isn’t being taken into account so it’s resizing both the top and bottom wedges on the same direction.

Here it is with only the bottom wedge working as intended:

Currently, I am adjusting the X axis position of the door to compensate for the resizing because the resizing is happening on the X axis.

This is what happens when the door is resizing on a different axis and it’s still positioning on the X axis to try and counter the resizing:

My question is, how do you position the objects locally regardless of their orientation? In the F3X plugin, there is this option called “local”, where instead of positioning based on the global axis, it will reposition it based on the object’s local orientation.

As seen here:

2 Likes

is it two parts seperated at each other?

1 Like

Mutiply by a CFrame rather than adding a vector.

CFrame = part.CFrame * CFrame.new(-part.Size.Y / 2, - (2 / 2), 0)

You have four elements in your Vector3, by the way. The fourth one is discarded.

1 Like

Yes, the door itself are 2 wedges

The top wedge is simply just the bottom wedge inverted

I’ll try that, also that was just a typo.

EDIT: I’ve got no clue what the math behind this is, but it is now working as intended, thanks.

2 Likes