Part Position and Orientation

Hello.

I’d like to rotate and position a part ontop of another part using the .Position and .Orientation properties.
I can’t use CFrame or Tweening as the part is Welded and Unanchored.

Code:

I manually did the math to determine the orientation and position changes, aswell as dividing it all by 1800 to get the amount to move each time the loop runs.

What it does:
https://gyazo.com/0a64144ce8d8e8a7f4294a68e63cf41e

https://gyazo.com/8d4997a1f1b3b735d744a0bdf7006915

The end product:

What I want it to do instead.
https://gyazo.com/92c1e3910a72d0c5290cf56f6ba14c66
Basically to rotate and move into the “Closed” position.
Preferable in one smooth movement, instead of rotating then moving separately.
I can provide more clearance if it is required.
Thanks!

2 Likes

First thing, you should be changing the X’s rotation and not the Z’s. And since this is a 90 degrees rotation, it would be easier to make a for loop, that loops from the 0 to 90, and use the i variable to add to the rotation

Then to rotate it as wanted, this way

for i = 0, 90, 1 do
     wait()
     local size = al.Size
     local pos = al.Position
     local cf = CFrame.new(pos.X, pos.Y-(size.Y/2), pos.Z)*CFrame.Angles(math.rad(i), 0, 0)*CFrame.new(0,size.Y/2,0)
     --we don't set it's cframe to cf, we're just gonna use cf to determine Position and Orientation
     local rx, ry, rz = cf:ToEulerAnglesXYZ()
     al.Orientation = Vector3.new(math.deg(rx), math.deg(ry), math.deg(rz))
     al.Position = cf.Position
end

I think this should work, if you want information on what I did visit this.

2 Likes

@starmaq I’m assuming this line of code closes with an ‘)’?

local rx, ry, rz = cf:ToEulerAnglesXYZ(

A slight issue. It does this.
https://gyazo.com/8de1096f0aad01a71cf8a4d13306479d

2 Likes