Animating points within a boxbuffergeometry

Greetings all,

Is there a straightforward method for animating individual particles to ‘float’ within a bounding box?

This may be a simple question, but it’s the last element to my first web project. Thanks!

I have a BoxBufferGeometry filled with points, very similar in construct to this [Torus Example].(https://codepen.io/prisoner849/pen/LgabWZ?editors=0010).

Here is a demo of me trying to give them a “kick” in space.
(Play one of the audios listed in the “Tracks” section on the left to see it in action.)

If you don’t need precise triangle collisions (for a box not relevant anyway) you can just use a simple bounding box check such as.

const box = new THREE.Box3;
box.expandByScalar( 50 ); // your box size, goes -50 for min and +50 for max so a 100x100x100 box 

// in your loop for checking particles
if ( !box.containsPoint( particlePosition ) )
	// do something

Depending on what you want to happen you could “kill” the particle going outside or just inverse the position so it wraps around the box, or reflect the particle off the box sides by it’s velocity vector, whatever you prefer.

I’m sorry, I’m still very new at absolutely everything. So I’ve been able to use the expandByScalar. I cannot seem to make the particles inside of the box move even with this technique.

Do you know of any examples or tutorials to show me quite what you mean?

Sorry i thought you wanted to know how to restrict them to move only inside a box. There are quite a lot examples about particles, just try the search in this forum or google, there are different approaches for different cases you can find what fits your needs.

@Wawki
Any explanatory picture (gif) or video of an effect, that similar to what you want to achieve, would be helpful.

@Fyrestar
I think you understood me correctly, and you’ve definitely set me on the right track!

To @prisoner849, I have now found a great example of this effect…I’m trying to reverse engineer it to just the simplest understandable mechanism:
https://threejs.org/examples/#webgl_buffergeometry_drawrange

@Wawki
Just for some ideas: Bouncing a sphere inside a box