0

I have this bezier curves that represent my flow of some particles. The problem is that I cannot seem to control the speed of the object unless I add more points on the bezier curve but that is inefficient..

enter image description here

These are my curves.

And my code is simply (in the animate() method):

function moveParticlesAlongCurve(particles,curvePoints){
  particles[0].position.x = curvePoints[i].x;
  particles[0].position.y = curvePoints[i].y;
  i++;
}

Any ideas on how to control the speed?

WestLangley
  • 102,557
  • 10
  • 276
  • 276
Trt Trt
  • 5,330
  • 13
  • 53
  • 86
  • See https://stackoverflow.com/questions/18400667/three-js-object-following-a-spline-path-rotation-tanget-issues-constant-sp/18409167#18409167 – WestLangley Mar 31 '18 at 02:36
  • thanks man I had to use .getPointAt( t ) instead of .getPoint( t ). – Trt Trt Mar 31 '18 at 12:05

2 Answers2

0

I image moveParticlesAlongCurve is called continuously and i is defined somewhere outside, you can try incrementing i inside a setTimeout to delay the next tick, see if that helps.

    function moveParticlesAlongCurve(particles,curvePoints){
      particles[0].position.x = curvePoints[i].x;
      particles[0].position.y = curvePoints[i].y;
      setTimeout(function(){ i++; }, 1000);
    }
bugs
  • 14,631
  • 5
  • 48
  • 52
0

To maintain a constant speed, you should use curve.getPointAt( t ) instead of curve.getPoint( t ).

There is more detail in this answer to a related question.

three.js r.91

WestLangley
  • 102,557
  • 10
  • 276
  • 276