# Creating Trail of Points Behind a Moving Object

I am creating a trail of points (SmkTot) behind a moving object (AirPtr). The points are part of a mesh (SmkPtr) which includes a BufferGeometry which includes these points. Each point in this mesh is assigned a position and an initial timer value which equals the point index value multiplied by an interval (SmkInt). The timer value for each point is incremented with each iteration. When the timer value for a point reaches a maximum value (SmkTot X SmkInt), the position of the point and the timer value are reset to “0”.

I created the set of points using this kind of subroutine:

``````// particle position and timer
for (let i = 0; i < SmkTot; i++) {
SmkPts.push(0,0,0);		// position
SmkTim[i] = i*SmkInt;		// timer
}
geometry = new BufferGeometry();
geometry.setAttribute('position', new Float32BufferAttribute(SmkPts, 3));
material = new PointsMaterial({size: SmkSiz, color: Co1});
SmkPtr = new Points(geometry, material);
// Link position of smoke mesh to position of moving object
SmkPtr.position.x = AirPtr.position.x;
SmkPtr.position.y = AirPtr.position.y;
SmkPtr.position.z = AirPtr.position.z;
``````

As noted above, the position of the smoke mesh is linked to the position of the moving object. The individual points are positioned relative to the position of the smoke mesh so that their position in the display appears to be stationary.

I updated the position of the points and the timer value using this kind of subroutine:

``````let pos = SmkPtr.geometry.attributes.position.array;
let p;
for (let i = 0; i < SmkTot; i++) {
p = 3*i;
// Change xyz position of each point by change in xyz position of moving object
pos[p] = pos[p] - SmkSMt.x;
pos[p+1] = pos[p+1] - SmkSMt.y;
pos[p+2] = pos[p+2] + SmkSMt.z;
SmkTim[i] ++;
// If timer value for point > max, then reset position and timer to "0"
if (SmkTim[i] > SmkTot*SmkInt) {
pos[p] = 0;
pos[p+1] = 0;
pos[p+2] = 0;
SmkTim[i] = 0;
}
}
SmkPtr.geometry.attributes.position.needsUpdate = true;
// Link position of smoke mesh to position of moving object
SmkPtr.position.x = AirPtr.position.x;
SmkPtr.position.y = AirPtr.position.y;
SmkPtr.position.z = AirPtr.position.z;
``````

The problem I am having is that the smoke trail disappears when the smoke mesh is offscreen.

NOTE

By pure luck (stupidity), I was able to avoid this clipping when I incorrectly defined SmkPts as:

``````let	SmkPts = ;
``````

This resulted in the following error message on initilization:

``````three.module.js:10181 THREE.BufferGeometry.computeBoundingSphere():
Computed radius is NaN. The "position" attribute is likely to have NaN values.
``````

The error message went away when I defined SmkPts as:

``````let	SmkPts = [];
``````

However, fixing my error created the clipping problem.

So, for now, I am living with the error.

QUESTION

Is there an easy way to fix what I have done to avoid both the error message and the clipping problem?

Is there a better way to do this (e.g. something out of the three.js examples)?

Here is a demo program that includes this trail of points (use the arrow keys to bank and pitch).