I am using boundary boxes for all calculations. In the image below you may see a case where this objects need to be snapped. Currently the calculations go as following, the rotation is changed by the minimal amount to match the object it is being snapped to: notice: The rotation is not set to the object as it can require minimal rotation to match without copying (axes are getting modified when rotating the object) Currently we check for nearest angle to rotate by checking for nearest angle constructed by 90 degree angles.

But here is the issue: as seen in the image below, the straight pipe can have virtually any rotation on the Y axis (the green one) and still not change visually, but when trying to snap the curved pipe to it, curved pipe takes the rotation of Y axis of the straight pipe. In user perspective, you should be able to turn the curved pipe around and have it set in any rotation (example in the other photo).

Other notes. The objects cannot be modified (say we cannot put certain gameobjects to use as a guide to who can connect to who) These objects may have their forward, up and right in different directions.

How can I find the axis on which no rotation should be applied? How can I nullify the rotation of the object by a single axis?

I tried to find matching axes with Dot Product. It was not performing as expected, somehow it works for X and Z axes but not for Y axis.


2 3



  • \$\begingroup\$ Why not store some simple properties on the GO for the special information like cannot be modified or which axis rotation should no rotation be applied? \$\endgroup\$
    – Zibelas
    Commented Jun 19 at 9:42
  • \$\begingroup\$ "I tried to find matching axes with Dot Product." Without seeing your code, we cannot tell you why this failed or how to fix it. Does your system include some metadata associated with these meshes, to know to snap the corner pipe at the part of the side of the box where it contacts the pipe end, and not at any of the parts of the box that are just open air? \$\endgroup\$
    – DMGregory
    Commented Jun 19 at 13:35
  • \$\begingroup\$ It should work dynamically. All models are imported at runtime, so I can't have predefined properties. However, I have already fixed this. First, I created a parent for the object and rotated the parent as needed without restricting one axis. Then, I calculated the difference between the initial rotation and the new rotation by multiplying quaternions and reversing one. After that, I set only the axis data that I needed to retain for the child object. Upon removing the child from the parent, I obtained the correct rotation. Thank you all for your help! \$\endgroup\$
    – Artak
    Commented Jun 20 at 10:16


You must log in to answer this question.

Browse other questions tagged .