# Rotate a mesh around a point on the mesh

**URL:** <https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668>\
**Category:** Questions\
**Created:** [September 15, 2019, 11:52pm UTC](https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668 "2019-09-15T23:52:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Notruilin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/notruilin/32/4593_2.png) [@Notruilin](https://forum.babylonjs.com/u/Notruilin)\
**Post date:** [September 15, 2019, 11:52pm UTC](https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668/1 "2019-09-15T23:52:59Z")

</div>

Hi there,  
I’m looking for a way to rotate the box around the sphere when dragging the slider like the picture below.  
[https://www.babylonjs-playground.com/#2Z4ERD](https://www.babylonjs-playground.com/#2Z4ERD)  
I’ve tried “[How To Rotate Around an Axis About a Point](https://doc.babylonjs.com/how_to/pivot)” but I must have misunderstood something.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/8/8cee473110bdc0ec4914b8ed0e4001a8ad8355de.png)  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/e/e93b49d521f04da867c8a2ba8aab8dd9b7e5ff2e.png)  
Thank you!

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [September 16, 2019, 12:26am UTC](https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668/2 "2019-09-16T00:26:33Z")

</div>

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

I edit your code here and reposition the camera correctly.  
[https://www.babylonjs-playground.com/#2Z4ERD#2](https://www.babylonjs-playground.com/#2Z4ERD#2)

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

---

<div class="post-metadata">

**Author:** ![Notruilin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/notruilin/32/4593_2.png) [@Notruilin](https://forum.babylonjs.com/u/Notruilin)\
**Post date:** [September 16, 2019, 1:27am UTC](https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668/3 "2019-09-16T01:27:32Z")

</div>

Hi,  
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. 😓 Could you help me? Thanks!

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [September 16, 2019, 9:35am UTC](https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668/4 "2019-09-16T09:35:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [September 16, 2019, 10:53am UTC](https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668/5 "2019-09-16T10:53:52Z")

</div>

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.

[https://www.babylonjs-playground.com/#2Z4ERD#3](https://www.babylonjs-playground.com/#2Z4ERD#3)

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. 🙂

---

<div class="post-metadata">

**Author:** ![Notruilin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/notruilin/32/4593_2.png) [@Notruilin](https://forum.babylonjs.com/u/Notruilin)\
**Post date:** [September 16, 2019, 11:23pm UTC](https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668/6 "2019-09-16T23:23:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Notruilin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/notruilin/32/4593_2.png) [@Notruilin](https://forum.babylonjs.com/u/Notruilin)\
**Post date:** [September 16, 2019, 11:47pm UTC](https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668/7 "2019-09-16T23:47:47Z")

</div>

😂Sorry, I got confused again.  
[https://www.babylonjs-playground.com/#2Z4ERD#4](https://www.babylonjs-playground.com/#2Z4ERD#4)  
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)?

---

<div class="post-metadata">

**Author:** ![Devin\_Wright](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/devin_wright/32/4302_2.png) [@Devin\_Wright](https://forum.babylonjs.com/u/Devin_Wright)\
**Post date:** [September 16, 2019, 11:56pm UTC](https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668/8 "2019-09-16T23:56:25Z")

</div>

recompute the world matrix.  
[https://www.babylonjs-playground.com/#2Z4ERD#5](https://www.babylonjs-playground.com/#2Z4ERD#5)

---

<div class="post-metadata">

**Author:** ![Notruilin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/notruilin/32/4593_2.png) [@Notruilin](https://forum.babylonjs.com/u/Notruilin)\
**Post date:** [September 17, 2019, 12:47am UTC](https://forum.babylonjs.com/t/rotate-a-mesh-around-a-point-on-the-mesh/5668/9 "2019-09-17T00:47:05Z")

</div>

It works. Thanks!😂
