0

How might I rotate an object around the axis of the world instead of the object itself? I've looked for an answer, but nothing has been working for me.

I made a hierarchy if swirls that I want to spin so that it looks sort of like waves. Unfortunately, even though I have checked and tested all my angles, it sways unlike it should, and I cannot get it to stay normal.

Here is a look at the functions I'm using:

function spinThePortal(portal, axis, speed, rotation) {
  if (axis === 0) {
    portal.rotation.y += speed;
  } else {
    portal.rotation.x += speed;
  }

  setTimeout(function () {spinThePortal(portal, axis, speed, rotation);}, 50);
}
function createPortals(firstDoubleCoor, secondDoubleCoor, number) {
  var direction = 1, notDirection = 0;
  if (firstDoubleCoor[0][0] === firstDoubleCoor[1][0]) {
    direction = 0; //vertical lines
    notDirection = 1;
  }
  var amount = difference(firstDoubleCoor[0][notDirection], firstDoubleCoor[1][notDirection]);
  var material = new THREE.MeshBasicMaterial({color: portalColorList[number]});
  var block = new THREE.CubeGeometry(baseSize / 20, baseSize / 20, baseSize / 20);
  function squiggle(coor) {
    var root = new THREE.Mesh(block, material);
    root.position.set(coor[0][0] * baseSize, coor[0][1] * baseSize, baseSize);
    var parent = root;
    for (var i = 0; i < amount * 43; i++) {
      object = new THREE.Mesh(block, material);
      object.position.x = baseSize / 30;
      parent.add(object);
      parent = object;
    }
    scene.add(root);
    root.traverse(function(object) {
      object.rotation.set(Math.PI / 10, Math.PI / 10, 0);
    });
    if (direction === 1) root.rotation.set(0, 0, -Math.PI / 4);
    else root.rotation.set(0, 0, Math.PI / 4);
    if (spinPortals) spinThePortal(root, direction, portalSpinSpeed, 0);
  }
  squiggle(firstDoubleCoor);
  squiggle(secondDoubleCoor);
}

I don't know what the problem is, but here is a link if you need to see my full creation: Click

WestLangley
  • 102,557
  • 10
  • 276
  • 276
Josiah Plett
  • 180
  • 14

0 Answers0