Using an Object's postion for an Event in AFrame

I’m trying to make a component that checks the current position of a sphere in an AFrame scene and when it hits a specific coordinate and when it does it fires an event (In example below it resets it to its default position):

AFRAME.registerComponent("trackball", {
  update: function() {
    let pos = this.el.getAttribute("position");
    if (pos == {x:-21.821,y: 1,z: 0})
      {
        this.el.setAttribute("position", "-21.821 5 0");
      }
  }
});

I’m not sure what format is returned when .getAttribute("position") is called so that may be why it’s not working. I am running AFrame 1.1.0.

26 thoughts on “Using an Object's postion for an Event in AFrame”

Leave a Comment