CFrame orientation problem

Hello, i’ve been trying to make a script that allows a part to be positioned in between two parts, so at first i used orientation and position to set its location but the model’s welds wouldnt follow the part as i had to use :PivotTo(), so i did so by converting my Vector3 orientation and position to a CFrame, however the orientation isnt right for some reasons.

Here is the code that calculates position orientation and that turns it into CFrame

local ori = ((articulation.FrontAt.Value.Orientation+articulation.BackAt.Value.Orientation)/2)-Vector3.new(90,0,0)
	local pos =  (articulation.FrontAt.Value.Position+articulation.BackAt.Value.Position)/2
	local gcf = CFrame.new( pos ) * CFrame.Angles( math.rad(ori.X),math.rad(ori.Y),math.rad(ori.Z))

And here is a screenshot of what it does instead of working properly

(The part in question is the gray one in the center)

What i dont understand is that it works perfection when setting the position and orientation separately (which i cant do due to welds not following)

1 Like

With CFrames you just use lookat

local gcf = CFrame.lookAt(pos, articulation.BackAt.Value.Position)

Then you have to make sure where your part should be looking at, in this case it is looking at articulation.BackAt.Value.Position. To make it look up you would do something like pos + Vector.new(0,1,0).

If you look at the documentation on Orientation you will notice that it is not that simple to use it with CFrames.

1 Like
CFrameA:Lerp(CFrameB, 0.5)

Lerp | Roblox Creator Documentation

If you need to rotate it a little bit, you can do:

CFrameA:Lerp(CFrameB, 0.5) * CFrame.Angles(0, 0, math.pi/2)
1 Like

Instead of CFrame.Angles, try CFrame.fromEulerAnglesXYZ. Angles applies rotation backwards: Z first, then Y, then X.

1 Like

I didnt know that angles was inverted, thanks for letting me know, allowed me to find out that the issue was the offset!

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