Array of Object3Ds

How can I subtract the x,y and z values of an object3d array? (x-2,y-2,z-2)

Your array looks more like of Vector3, not of Object3D.
If you want operations with uniform values, then use .xxxScale() methods. For example, in your case with subtraction of 2, it will be something like this: arrayOfVector3.forEach(v => {v.subScalar(2)});
Otherwise, if you want to perform operations with vectors, then use respective methods (.add(), .addVectors(), .sub(), .subVectors() etc.).

It doesn’t work , the cubePosition array’s number don’t changes

here is a part of my code :

const cubePositions = [];

cubePositions.forEach((v) => {

function init() {
  for (var i = 1; i < count; i++) {
    let angle = somthing...
    let radius = somthing...

    const x = somthing...
    const z = somthing...
    const cubePosition = new THREE.Vector3(x, -1, z - 2);

Then better to provide a minimal editable live-code working example. With more detailed desctiption, and ref pics of what you have and what you want to get in the result.:thinking:

Codepen Example

Here is my example

I want the radius of the cube to change when I click on the model
But now as you see
The radius changes randomly because the radius contains a random Math.random() value

I think if I can create an array of the current position of the cubes and subtract it by a static number, I might be able to use that.
This is just an idea

Is this the behaviour you’re trying to achieve?

Yes, Exactly

Then why do you use random values in onUpdate of gsap?

Save initial positions of instances, casting them into two things: direction and length.
And then, when you use gsap, you add current value of shift to saved length, and use the result to multiply direction.

It is hard for me to understand what you are saying.
It sounds like what you say is true
Can you help me write the proper code for this solution?

Here is the example:

I appreciate you.

How can I have not cubes in this area every time I refresh the browser, I want it not to be a 360 degree circle, I want the cubes to be on a 270 degree circle.

Please, put some effort in reading docs and studying trigonometry.

You can implement it yourself, using random value, 270 degs, radius, sine and cosine functions.
Creativity is up to you.

1 Like

I wrote this before but in your example i don’t know where i can put the radius and angle
I have edited dir line and it works now.
Thanks for you help

There is a problem in the code.
It only works properly when they have a fixed scale.
When the random scale is given to the cubes, the problem you see in the picture is created again.

I have Updated the example.

As you can see cubefloorScale has a static scale value and works well unlike cubeScale.

Try storing the scale of each instance in d.userData.scale to preserve synchronicity of scales over each iteration. You’re adding Math.Random to the scale of each everytime you update the matrices like this…


Thanks for your help :+1:t2:

1 Like