CFrame math problem

this did not work, this is my exact code:

local grayPart = workspace.Model["Gray Part"] -- primary part
local greenPart = workspace.Model["Green Part"]
local redpart = workspace["Red Part"]

local offset = grayPart.Position - greenPart.Position
workspace.Model:PivotTo(CFrame.lookAt(grayPart.Position, redpart.Position + offset))

and here is the result:
image

No i do not want snapping 30 carrs

Why not just put the Pivot point in the center of the grey square?

rotate the gray part by 90 degrees counter clockwise and rescale it. Should work

edit:
you might have to keep rotating it. Just get it so the front face of the gray part is looking at the green part

lookat.rbxl (41.4 KB)
Updated by putting pivot position inside gray square

i don’t want to change the pivot position because it would mess up my other pivots and then we would be at square one.

Ah alright. I will try something

if you dont wanna rotate the gray paart just add an invisible part with same pos as the gray part. But make its front face look at the green part. Make the invis part the Primary Part

lookat.rbxl (41.6 KB)

Try this, it doesnt change pivot position, it does offset via code

this does not keep the same rotational offset

Elaborate on what you mean by rotational offset? Because lookvector is the way you’re supposed to achieve what you’re asking for

For example:
image
the green part is rotated 90 degrees on the y axis from the gray part

Maybe this works

local grayPart = workspace.GrayPart -- gray part
local greenPart = workspace.GreenPart -- green part

local greenToGray = greenPart.CFrame:ToObjectSpace(grayPart.CFrame)
local grayToGreen = grayPart.CFrame:ToObjectSpace(greenPart.CFrame)

local function Target(pos) -- pass the position to target
	local grayToPos = CFrame.lookAt(grayPart.Position,pos)
	local greenPos = grayToPos*grayToGreen.p
	local greenToPos = CFrame.lookAt(greenPos,pos)
	local dir = grayToPos:Lerp(greenToPos,.5).Rotation
	grayPart.CFrame = dir+grayPart.Position
	greenPart.CFrame = grayPart.CFrame*grayToGreen
end

Target(workspace.Target.Position) -- how you use

Just modify the lines with comments

I tried it but…
it’s still not working :frowning: