# About Physics Engine!

**URL:** <https://forum.babylonjs.com/t/about-physics-engine/6178>\
**Category:** Questions\
**Created:** [October 8, 2019, 11:25am UTC](https://forum.babylonjs.com/t/about-physics-engine/6178 "2019-10-08T11:25:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shhuangcheng](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shhuangcheng/32/4824_2.png) [@shhuangcheng](https://forum.babylonjs.com/u/shhuangcheng)\
**Post date:** [October 8, 2019, 11:25am UTC](https://forum.babylonjs.com/t/about-physics-engine/6178/1 "2019-10-08T11:25:51Z")

</div>

Hi,  
I have a question about Physics engine.  
I want rotate the physicsRoot,but this line ( physicsRoot.rotation.y += 0.1;) does not effect.  
I have used unity,if I use physics engine,it can do well.  
if I remove the line (physicsRoot.physicsImpostor = new BABYLON.PhysicsImpostor(physicsRoot, BABYLON.PhysicsImpostor.NoImpostor, { mass: 3 }, scene);),it can effect,however it has no physics effect.  
I don’t know why? Can you help me? Thanks a lot!

The relative code as follow:

var createScene = function () {  
var scene = new BABYLON.Scene(engine);  
var camera = new BABYLON.FreeCamera(“camera1”, new BABYLON.Vector3(0, 5, -10), scene);  
camera.setTarget(BABYLON.Vector3.Zero());  
camera.attachControl(canvas, true);  
var light = new BABYLON.HemisphericLight(“light1”, new BABYLON.Vector3(0, 1, 0), scene);  
scene.enablePhysics(new BABYLON.Vector3(0,-10,0), new BABYLON.AmmoJSPlugin());  
var ground = BABYLON.Mesh.CreateGround(“ground1”, 6, 6, 2, scene);  
ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, friction: 0.5, restitution: 0.7 }, scene);

```
// Import mesh and set colliders
BABYLON.SceneLoader.ImportMesh("", "scenes/", "skull.babylon", scene, function (newMeshes) {
    // Scale loaded mesh
    newMeshes[0].scaling.scaleInPlace(0.01);
    newMeshes[0].position.set(0,0,0)

    var boxCollider = BABYLON.Mesh.CreateBox("box1", 0.3, scene);
    // Create a physics root and add all children
    var physicsRoot = new BABYLON.Mesh("", scene);
    physicsRoot.addChild(newMeshes[0]);
    physicsRoot.addChild(boxCollider);
    physicsRoot.position.y+=3;
    physicsRoot.rotation = new BABYLON.Vector3(0,Math.PI/2,0);

    // Enable physics on colliders first then physics root of the mesh
    boxCollider.physicsImpostor = new BABYLON.PhysicsImpostor(boxCollider, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0 }, scene);
    physicsRoot.physicsImpostor = new BABYLON.PhysicsImpostor(physicsRoot, BABYLON.PhysicsImpostor.NoImpostor, { mass: 3 }, scene);

    setInterval(()=>{
        physicsRoot.rotation.y += 0.1;
    },100)        
});
return scene;

```

};

---

<div class="post-metadata">

**Author:** ![Givo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/givo/32/4968_2.png) [@Givo](https://forum.babylonjs.com/u/Givo)\
**Post date:** [October 8, 2019, 11:42am UTC](https://forum.babylonjs.com/t/about-physics-engine/6178/2 "2019-10-08T11:42:51Z")

</div>

Hey! I have an easy solution. Whenever you are using a physicsimpostor, you have to use rotation Quaternion. Works the same was as a plain rotation for non-physics meshes. I even made a little demo for you: [https://www.babylonjs-playground.com/#BEFOO#397](https://www.babylonjs-playground.com/#BEFOO#397)

rotation Quaternion does have a sort of limit, though, so you can’t have a loop that rotates it forever. I think.

(P.S. when using code in the forums, you can use ``` on the line above and below your code to make it all look nice.)

```auto
sphere.rotationQuaternion = 5;

```

---

<div class="post-metadata">

**Author:** ![shhuangcheng](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shhuangcheng/32/4824_2.png) [@shhuangcheng](https://forum.babylonjs.com/u/shhuangcheng)\
**Post date:** [October 8, 2019, 12:14pm UTC](https://forum.babylonjs.com/t/about-physics-engine/6178/3 "2019-10-08T12:14:51Z")

</div>

Yes,It does well.thank you very much.

There is something wrong.It can do well,if you modify these codes:  
var yaw = 0;  
var pitch = 0;  
var roll = 0;

```
scene.registerBeforeRender(function () {
    if(inputMap[" "]){
        pitch += 0.1;
        sphere.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(yaw, pitch, roll);
    } 
});

```

Thank you again!  
I think it maybe a bug of Babylon.js.

---

<div class="post-metadata">

**Author:** ![Givo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/givo/32/4968_2.png) [@Givo](https://forum.babylonjs.com/u/Givo)\
**Post date:** [October 8, 2019, 12:29pm UTC](https://forum.babylonjs.com/t/about-physics-engine/6178/4 "2019-10-08T12:29:12Z")

</div>

I made a playground with the issue. [https://www.babylonjs-playground.com/#BEFOO#398](https://www.babylonjs-playground.com/#BEFOO#398) I’m not sure what is going on, but the console might have an error in it. If you are using chrome, just open the link and press ctrl+shift+i to open the console. ~~I’ll try and figure out who to ping.~~ @Deltakosh who knows the physics engines?

---

<div class="post-metadata">

**Author:** ![shhuangcheng](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shhuangcheng/32/4824_2.png) [@shhuangcheng](https://forum.babylonjs.com/u/shhuangcheng)\
**Post date:** [October 8, 2019, 12:33pm UTC](https://forum.babylonjs.com/t/about-physics-engine/6178/5 "2019-10-08T12:33:46Z")

</div>

you should modify this line with var pitch = 0;

---

<div class="post-metadata">

**Author:** ![Givo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/givo/32/4968_2.png) [@Givo](https://forum.babylonjs.com/u/Givo)\
**Post date:** [October 8, 2019, 1:20pm UTC](https://forum.babylonjs.com/t/about-physics-engine/6178/6 "2019-10-08T13:20:32Z")

</div>

Oh, right. I’m used to initializing variables and setting them later.  
[https://www.babylonjs-playground.com/#BEFOO#399](https://www.babylonjs-playground.com/#BEFOO#399)  
This works, so what’s the issue?
