How can I manipulate the Size of a BasePart to eliminate unnecessary CFrame components?
What I'm trying to do:
I want to encode the CFrame of a part, but hopefully eliminate the rotation matrix if it is unnecessary (all bricks will end up facing upwards, and that is fine). For example, if the Rotation = Vector3.new(90, 0, 0)
then we can remove the need to encode rotation by switching the z and y coordinates of Size: Size = Vector3.new(Size.x, Size.z, Size.y)
I don't want to modify the rotation or Size of the part I am encoding, so I want to manipulate the data only.
Here is unconfirmed ways you are supposed to manipulate the xyz's:
01 | Rot = Vector 3. new( 0 , 0 , 0 ) |
02 | Size = Vector 3. new(x, y, z) |
04 | Rot = Vector 3. new( 0 , 0 , 90 ) |
05 | Size = Vector 3. new(y, x, z) |
07 | Rot = Vector 3. new( 0 , 90 , 0 ) |
08 | Size = Vector 3. new(z, x, y) |
10 | Rot = Vector 3. new( 90 , 0 , 0 ) |
11 | Size = Vector 3. new(x, z, y) |
13 | Rot = Vector 3. new( 90 , 90 , 0 ) |
14 | Size = Vector 3. new(y, z, x) |
16 | Rot = Vector 3. new( 90 , 0 , 90 ) |
17 | Size = Vector 3. new(z, x, y) |
Also keep in mind there are positive and negative 90's and 180's, those are the same to us, so let's narrow the possibilities:
4 | if brick.Rotation.x = - 90 then brick.Rotation = Vector 3. new( 90 , brick.Rotation.y, brick.Rotation.z) end |
5 | if brick.Rotation.y = - 90 then brick.Rotation = Vector 3. new(brick.Rotation.x, 90 , brick.Rotation.z) end |
6 | if brick.Rotation.z = - 90 then brick.Rotation = Vector 3. new(brick.Rotation.x, brick.Rotation.y, 90 ) end |
7 | if brick.Rotation.x = = 180 or brick.Rotation.x = = - 180 then brick.Rotation = Vector 3. new( 0 , brick.Rotation.y, brick.Rotation.z) end |
8 | if brick.Rotation.y = = 180 or brick.Rotation.y = = - 180 then brick.Rotation = Vector 3. new(brick.Rotation.x, 0 , brick.Rotation.z) end |
9 | if brick.Rotation.z = = 180 or brick.Rotation.z = = - 180 then brick.Rotation = Vector 3. new(brick.Rotation.x, brick.Rotation.y, 0 ) end |
This is how you isolate the Rotation Matrix in a CFrame:
1 | local rotation = part 1. CFrame - part 1. Position |
2 | local x, y, z, R 00 , R 01 , R 02 , R 10 , R 11 , R 12 , R 20 , R 21 , R 22 = rotation:components() |
I don't expect anyone to write this script for me. What I would like to know from someone, is if it is possible to write this script without manually checking for each specific case, and then acting accordingly. Again, the script can't modify the Brick we are finding the CFrame of. Any ideas?