Search code examples
aframe

Why coordinates are not placing them relative to each other?


Why is they stick together? and still showing -20 on x axis position? enter image description here

    <html>
  <head>
    <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
  </head>
  <body>
    <a-scene>
      <a-box  scale="0 1 1" color="#ca96fd" position="0 0 0 ">
        <a-box color="#FF0000" scale="0 1 1" position="-20 0 0" >
        </a-box>
       </a-box>
    </a-scene>
  </body>
</html>
<html>
  <head>
    <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
  </head>
  <body>
    <a-scene>
        <a-box  scale="1 1 1" color="#ca96fd" position="1 0 0 ">
        <a-box color="#FF0000" scale="1 1 1" position="-2 0 0" >
        </a-box>
        </a-box>
    </a-scene>
  </body>
</html>

When I put scale for both the boxes "1 1 1" and and position of box1="1 0 0" and position of box2="-2 0 0". Then also it shows -2 for box2 which is in relative to box1. Shouldn't be it -1? Because box1 on x-axis is at 1 from origin. Whereas box2 is in relative to box1 on x-axis, so 1-2 = -1. Box2 should be on -21 from origin.

To see the position look at top right under

enter image description here


Solution

  • When you set scale = "0 1 1", you are crompressing the entire X axis for this object and all its children to zero.

    That explains why an x offset of 20 on the child has no effect.

    If you want to scale onee box, without scaling the other, make them siblings, rather than parent-child.

    <a-scene>
      <a-box  scale="0 1 1" color="#ca96fd" position="0 0 0 ">
      </a-box>
      <a-box color="#FF0000" scale="0 1 1" position="-20 0 0" >
      </a-box>      
    </a-scene>
    

    Alternatively, you can use an a-plane instead of an a-box. An a-plane is already flat, so you don't need to scale the x dimension by zero. You may need to rotate it to get it into the poisition you want, in which case bear in mind that the position co-ordinates of any children will also be rotated.

    Related to your final point, the positions shown in A-Frame inspector are the positions relative to the parent, not the positions in world space.

    So A-Frame inspector reports a position of -2, but the world-space position in which the object is actually drawn will be -1 (1 from the parent and -2 from the child).