In my code, I have implemented a render loop to attach a cube to the end of a line called BuffGeometry line
. Everything works well when I set the line's geometry.SetDrawRange
to (0, drawRange).
line1.geometry.setDrawRange(0, drawCount);
line2.geometry.setDrawRange(0, drawCount);
//blahblah
var positioning = buffGeometry2.getAttribute('position');
if (drawCount%3 == 0){
cube.position.x = positioning.array[drawCount*3 + 0];
cube.position.y = positioning.array[drawCount*3 + 1];
cube.position.z = positioning.array[drawCount*3 + 2];
}
However, I encountered a problem when trying to limit the length of the line with
geometry.SetDrawRange(drawRange-20, drawRange)
. This caused the cube's position to be out of sync with the line's head position. To fix this issue, I made some changes to the setDrawRange
lines:
if (drawCount > 20){
line1.geometry.setDrawRange(drawCount-20, drawCount);
line2.geometry.setDrawRange(drawCount-20, drawCount);
}
else{
line1.geometry.setDrawRange(0, drawCount);
line2.geometry.setDrawRange(0, drawCount);
}
As a result of these changes, the cube now stays on the line's path when the draw limit is reached (after 20 steps), but it struggles to keep up with the line's pace.
Thank you