How to move a part to position with it's offset based on orientation of another part?

So, I have a part (let’s call A) in the workspace. I’m try to move another part (lets call B) to A, but offsetting it by 5 units INFRONT of A.

To clarify: if A’s front is facing in the positive y direction, then part B needs to be placed 5 units above part A. If A’s front is towards the negative y direction, the part B needs to be placed 5 units below part A.

Getting the position of the part is easy, but I can’t figure out how to get a position based on the orientation of the part.

Here’s something I found on the DevHub.

Is this what you were looking for?

Here is how it works. CFrame:ToWorldSpace is used to offset parts like this.

local redBlock = game.Workspace.RedBlock
local blueCube = game.Workspace.BlueCube
 
local offsetCFrame = CFrame.new(0, 2, 0)
redBlock.CFrame = blueCube.CFrame:ToWorldSpace(offsetCFrame)
4 Likes

Now considering that I have a lot of experience in this, it hurts me to say that I’m not entirely sure if my answer is completely correct on this issue.

What I propose is to go ahead and try using CFrame.LookVector to base your position off of. I am 20% sure this is what you should use. But besides the point, you should probably search the Developer Hub for possible API references. (Like @TheCarbyneUniverse just posted)

1 Like

Yeah I’ve been reading over that, but I still really can’t figure it out. I promise I’m not just wanting a quick answer, I’ve been trying to do this on my own for an hour lol I’m just not getting it.

Ok the code provided worked for me! Idk what I was doing wrong, but I was making it way to complicated

1 Like