# Changing the mesh rotation in onBeforeRenderObservable resets position for physics objects

**URL:** <https://forum.babylonjs.com/t/changing-the-mesh-rotation-in-onbeforerenderobservable-resets-position-for-physics-objects/16956>\
**Category:** Bugs\
**Created:** [December 27, 2020, 5:57am UTC](https://forum.babylonjs.com/t/changing-the-mesh-rotation-in-onbeforerenderobservable-resets-position-for-physics-objects/16956 "2020-12-27T05:57:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![blindinghues](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blindinghues/32/15289_2.png) [@blindinghues](https://forum.babylonjs.com/u/blindinghues)\
**Post date:** [December 27, 2020, 5:57am UTC](https://forum.babylonjs.com/t/changing-the-mesh-rotation-in-onbeforerenderobservable-resets-position-for-physics-objects/16956/1 "2020-12-27T05:57:14Z")

</div>

> **[Babylon.js Playground](https://playground.babylonjs.com/#BEFOO%23946)**

Not sure what other info to give, I made this playground to demonstrate. Really bizarre, took my ages to find out the cause.

---

<div class="post-metadata">

**Author:** ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)\
**Post date:** [December 27, 2020, 8:41am UTC](https://forum.babylonjs.com/t/changing-the-mesh-rotation-in-onbeforerenderobservable-resets-position-for-physics-objects/16956/2 "2020-12-27T08:41:46Z")

</div>

I wonder if it’s because when using a Physics Engine, we should only be setting `rotationQuaternion` and not `rotation`

> [@Child in physics compound body not rotated properly under Ammo.js and Oimo](https://forum.babylonjs.com/t/child-in-physics-compound-body-not-rotated-properly-under-ammo-js-and-oimo/13291/8):
>
> This is there to explain that the physics engines convert your rotation to quaternions so don’t use .rotation after setting a physics impostor. I do agree however that you can understand this sentence a bit differently slight_smile This is certainly a bug, and it seems like the extent size change is the way to go. There was a reason why we decided to use extendSizeWorld, so I will have to see when what should be used. The logic is clear thou wink Want to report an issue on github so we ca…

@RaananW would understand this better 🙂

In this PG, a new `rotationQuaternion` is assigned: [https://playground.babylonjs.com/#BEFOO#947](https://playground.babylonjs.com/#BEFOO#947)

---

<div class="post-metadata">

**Author:** ![blindinghues](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blindinghues/32/15289_2.png) [@blindinghues](https://forum.babylonjs.com/u/blindinghues)\
**Post date:** [December 29, 2020, 12:39pm UTC](https://forum.babylonjs.com/t/changing-the-mesh-rotation-in-onbeforerenderobservable-resets-position-for-physics-objects/16956/3 "2020-12-29T12:39:58Z")

</div>

Thanks for the playground. I ended up just using rotation.copyFrom, not sure if that has any other unintended consequences, but it looks to be play fine with physics.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 4, 2021, 9:53am UTC](https://forum.babylonjs.com/t/changing-the-mesh-rotation-in-onbeforerenderobservable-resets-position-for-physics-objects/16956/4 "2021-01-04T09:53:23Z")

</div>

When creating an impostor, the physics engine takes the current rotation from the .rotation object and transforms it to a rotationQuaternion, unless a rotationQuaternion is already available. Re-setting the .rotation object will not work (as you noticed), as the physics engine will take the old rotation. using copyFrom will keep the object and not re-create it, so it works. Setting the rotationQuaternion as @gbz mentioned would have worked as well 🙂
