Mesh is sticking into another

Hi guys,

I have an issue where I create one mesh (sphere) and right after I create a box, I animate only the sphere but the box is in somehow attached to the sphere, I didn’t add a parenting command.

this is the pg:

https://playground.babylonjs.com/#IA3AYT#11

I’m trying to animate them independently but first I need to achieve they don’t stick together.

thanks

At lines 55 and 68, when you assign the node’s position:
pacman.position = myPathR[0];

You’re actually assigning the pacman.position and pix.position reference to point to the myPathR[0] vector.

(When the pacman object is animated across the path, the myPathR[0] and pix.position value will change with the pacman node’s position, yikes!)

To fix this, you should instead use:
pacman.position.copyFrom(myPathR[0]);

When you want to copy values from one vector to another, that you expect to modify independently.

4 Likes

Thank you for the explanation. It is due reference values of the vector object?

I’ll follow your fix and let you know how it goes.

Thanks again!!!

Yes, since Vector3 is not a primitive type, it is passed by reference, rather than by value.

2 Likes

Thank you very much! I believed I knew a lot about objects but it seems I have many things to learn still :slight_smile:

Thank you it worked as a charm!

https://playground.babylonjs.com/#IA3AYT#12

2 Likes