Weld Orientation Changes?

Hello,

So I made a script that changes the weld orientation. However, I encounter the problem that the weld changes itself.

Script below:

Weld.C1 = CFrame.Angles(math.rad(90), math.rad(-90), 0)

However, when viewed in the game, it different and it messes up the orientation.
image

How can I fix this?

Thank you.

Try using CFrame.fromOrientation instead. It will change the actual CFrame as it will do the rotation on the Y axis first then on the X axis (unlike .Angles which is the inverse)

1 Like

Wait, how am I supposed to change the position of the weld aswell?

Change the Weld C0 or C1 Position.
If you don’t set C0 or C1 it’ll just Position it at 0,0,0 in both Part0 and Part1.

How would I change the position though? I get this when attempt to change it.
image

You have to include it in the C1 CFrame (or C0, while you can do everything with C0 or C1 alone, having both of them can be useful sometimes)

Weld.C1 =  CFrame.fromOrientation(math.rad(90), math.rad(-90), 0) * CFrame.new(10,0,0)

CFrames contain both position and orientation, and if you understand them well, they basically replace the position property of objects, and especially orientation (CFrames are much more useful than Euler angles). They are harder to understand though

Something else to note is that the order in which you do your operations matters, for example, here is the difference between doing the angle first, or the position first:
image
(I didn’t bother write math.rad in this figure)
CFrame math is always “relative”. In the case where the orientation is done first, then the position, the position is relative to that orientation, making it to 10 studs at 45°. This leads to different results depending on the order of operations

3 Likes

Thank you so much for giving me visual on how it works! :pray:

2 Likes

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