I have many cubes in the scene randomly placed in a circle
I want to place an object in a static position and remove the cubes there
How to remove cubes at a certain point?
for (var i = 1; i < count; i++) {
let angle = somthing;
let radius = somthing;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
const cubePosition = new THREE.Vector3(x, 0, z);
Well you can take 2 aproches based what you render first.
I asume in this example you generate cylinders randomly, if that is not the case it will be even easier.
If you generate the cubes first you can store the randomly generated x and z coordinates of the cubes in a variable. The type of data you would store them in is up to you but I would probably go for an array.
After the cube loop is finished and you have your stored coordinates you can start generating the cylinders.
When you generate the cylinders the rules should be quite simple.
If the position of the generated cylinder dose not mach any of the data that is in your position variable ( + an additional offset based on the size of your cubes and cylinders, which you can get thru try and error ) the cylinder should be generated, if it does match any of the positions the loop should run again. Keep in mind that when a new cylinder js generated you will have to add his position to the cube position varibale so it does not interact with the other cylinders.
And if you generate the cylinders first you just do the opposite.
I checked your solution
In this solution, you assume that the cubes are created and then the cylinders look for empty spaces to create.
The point is that I don’t want the cubes to be created at the point where the cylinders are created, rather than the cylinders looking for empty space to create.
In two modes with random or predetermined cylinder position.
Another point is that the cylinders are GLTF models
All I have is the position of the cubes in an array and the position of each cylinder in a separate vector3 variable.