0

I am trying to move an a-frame sphere using jquery attr().

I used this in the script tag(the a-sphere is already there with the id sphere.):

  var x = '0 5 0';
  $("#sphere").attr('position', x);

It doesn't work. Is there a different way to change it or do I have a mistake?

ry kim
  • 93
  • 9
  • You can maybe find something here : https://stackoverflow.com/questions/42041517/how-do-i-rotate-a-box-in-a-frame-by-moving-or-dragging-the-mouse – SKJ Aug 09 '20 at 22:44
  • It is about rotating with drag, but this is changing the position/ – ry kim Aug 10 '20 at 02:15

1 Answers1

1

Use setAttribute. More info in A-Frame docs

$("#sphere")[0].setAttribute('position', {x: 1, y: 2, z: 3});

FYI, you can also use the standard DOM querySelector instead of jQuery

document.querySelector(“#sphere”).setAttribute('position', {x: 1, y: 2, z: 3});

If still doesn’t work I recommend sharing code that people can run and debug. Glitch is great

Diego Marcos
  • 4,502
  • 3
  • 15
  • 20