Position Part Relative To Two Other Parts On Certain Axises While Taking Rotation Into Account

I have 3 parts: the blue part (A), red part (B), and the grey part in the background (C)

I want A (the blue part) to have a new position or cframe that has the X cframe of the red part, and the Y and Z of the grey part.

I’ve tried ToWorldSpace() and VectorToWorldSpace(), but ultimately I can’t get it to work.

Keep in mind I need them to align in the way I stated above while taking rotation into account.

Could you show an image of what the result would look like?

It should look identical if not more accurate in the image above, the blue part should be aligned by the X axis of the red part, and Y,Z should be aligned with the grey part.

With rotation of the grey part taken into account.

local greyPart = ...
local bluePart = ...
local redPart = ...

local rx, ry, rz = greyPart.CFrame:ToOrientation()

bluePart.CFrame = CFrame.new(redPart.CFrame.Position.X, greyPart.CFrame.Position.Y, greyPart.CFrame.Position.Z) * CFrame.fromOrientation(rx, ry, rz)

Maybe something like this?

Nothing happened not even errors, but I’ve already tried using ToOrientation()

When I used it yesterday it did work, but the Z axis wasn’t fully aligned with the grey part.

Yeah ToOrientation() probably isn’t going to satisfy my problem, I’ve got so close with just multiplying cframes, but they are never fully aligned…

You could just set the CFrame by reading off some position values and adding it to the rotation cframe of the grey part.

local BluePart, RedPart, GreyPart = --Blue, Red, and grey
local  RedPos, GreyPos = RedPart.Position, GreyPart.Position
local GoalRot = GreyPart.CFrame.Rotation --Get blank rotation data, no position data
local GoalPos = Vector3.new(RedPos.X, GreyPos.Y, GreyPos.Z) --create a position from your specifications
BluePart.CFrame = GoalRot + GoalPos --add the rotation to the position

Doesn’t work… Although I’ll take your reply into consideration, honestly I was oblivious to there being a .Rotation of a CFrame.

Solved my own problem. :sunglasses:

local GreyPart, RedPart, BluePart = workspace.GreyPart, workspace.RedPart, workspace.BluePart;
local X = -(RedPart.CFrame:ToObjectSpace().X - RedPart.Size.X/2 - GreyPart.CFrame:ToObjectSpace().X);

BluePart.CFrame = GreyPart.CFrame:ToWorldSpace(CFrame.new(X,0,0));

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