Rotate a mesh around a point on the mesh

Hi there,
I’m looking for a way to rotate the box around the sphere when dragging the slider like the picture below.
I’ve tried “How To Rotate Around an Axis About a Point” but I must have misunderstood something.

Thank you!

1 Like

Use : setPivotPoint(new BABYLON.Vector3(-2.5, 2.5, 0), false);

I edit your code here and reposition the camera correctly.

The changes are on the line 23, and the function slider.onValueChangedObservable.add() line 38 where I removed all that was useless.


Thank you so much.
May I ask why it is “new BABYLON.Vector3(-2.5, 2.5, 0)”? Is it local position or world position?

I used “myBox.getAbsolutePivotPoint()” before setPivotPoint and the output is {X: 0 Y:0 Z:0}.
From my understanding, the absolute pivot would not be (0,0,0) after I move the box to (5, 2.5, 0) on the line 15. :sweat: Could you help me? Thanks!

Your box is 5 units. The pivot being in the center, I back 2.5 on the X axis and then back up 2.5 on the Y axis so that the pivot is at the level of the sphere.

Hi guys. @Notruilin , you may wish to study localSpace and worldSpace a bit.

LocalSpace generally means: As-measured-from/in-relation-to… the center of the mesh itself.

WorldSpace generally means: As-measured-from/in-relation-to… the center of the world/scene.

In the above PG, notice I added two lines: 25/26. Run your scene and look at console. Notice the difference.

Now change your box position in lines 15/16. Run again. See how the “absolute” (worldspace) version… changes pivot location along-with the mesh’s (worldSpace) position.

The non-absolute localSpace pivotpoint… does not change. It is at the same localSpace position (as measured from center of box), no matter where within worldSpace… that you position the box.

With me? I hope so. It takes some time/practice to determine WHEN something is measured/positioned in localSpace, and when in worldSpace. I hope I was helpful. :slight_smile:


Oh that’s why. I think I got it.:smile: Thank you so much!

1 Like

:joy:Sorry, I got confused again.
I printed the local and world positions of pivot in lines 18/19 and they are both (0,0,0).
However, myBox has been moved to (5,2.5,0) in lines 15/16, so why the worldSpace pivotpoint isn’t (5, 2.5, 0)?

recompute the world matrix.


It works. Thanks!:joy: