代码之家  ›  专栏  ›  技术社区  ›  blue

三个J-鼠标反方向?

  •  0
  • blue  · 技术社区  · 6 年前

    好吧,我下班了 https://tympanus.net/codrops/2018/12/06/interactive-repulsion-effect-with-three-js/ Three.js - Push away and then restore elements position on "mouse move"

    我用的是TweenMax,可以像这样改变物体的位置

    TweenMax.to(m.position, .2, { x: 0, y: 0, z: 0});
    

    const distance = (x1, y1, x2, y2) => {
      return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2));
    }
    
    const distancexyz = (x1, y1, z1, x2, y2, z2) => {
      return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2)+ Math.pow((z1 - z2), 2));
    }
    

    三.js-推开,然后在“鼠标移动”时恢复元素位置 .

    我怎样才能使物体朝着与鼠标相反的方向移动,就像所有轴上的排斥一样?

    可以使用TweenMax将对象移动到某个方向(我没有鼠标方向,这是我需要的):

     TweenMax.to(m.position, duration, { x: change, y: change, z: change});
    
    0 回复  |  直到 6 年前