# Can't make my mesh rotate

**URL:** <https://forum.babylonjs.com/t/cant-make-my-mesh-rotate/24459>\
**Category:** Questions\
**Created:** [October 10, 2021, 4:41pm UTC](https://forum.babylonjs.com/t/cant-make-my-mesh-rotate/24459 "2021-10-10T16:41:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brunozerouno](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brunozerouno/32/21051_2.png) [@Brunozerouno](https://forum.babylonjs.com/u/Brunozerouno)\
**Post date:** [October 10, 2021, 4:41pm UTC](https://forum.babylonjs.com/t/cant-make-my-mesh-rotate/24459/1 "2021-10-10T16:41:53Z")

</div>

Hello, could you please help me with this: My mesh won’t rotate along y axis for some reason.

```auto
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Babylon test page</title>

        <style>
            html, body {
                overflow: hidden;
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;
            }

            #renderCanvas {
                width: 600px;
                height: 600px;
                touch-action: none;
				border: thin solid red;
            }
        </style>

<script src="https://cdn.babylonjs.com/babylon.js"></script>
<!--<script src="https://cdn.babylonjs.com/inspector/babylon.inspector.bundle.js"></script>-->
<script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
<!--<script src="https://code.jquery.com/pep/0.4.3/pep.js"></script>-->
	<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.1.min.js"></script> 
<!--<script src="https://cdn.babylonjs.com/postProcessesLibrary/babylonjs.postProcess.min.js"></script>
<script src="https://cdn.babylonjs.com/gui/babylon.gui.min.js"></script>-->
	
	
		
	
    </head>

   <body>

    <canvas id="renderCanvas" touch-action="none" data-camdistance="160" data-camerax="0" data-cameray="50" data-cameraz="0" data-meshname="glTF"></canvas> <!-- touch-action="none" for best results from PEP -->

 
	   
	   
	   
    <script type="text/javascript">

		
        const canvas = document.getElementById("renderCanvas"); // Get the canvas element
        const engine = new BABYLON.Engine(canvas, true); // Generate the BABYLON 3D engine

        // Add your code here matching the playground format
        const createScene = function () {
    
        const scene = new BABYLON.Scene(engine);  

			
			
	var defaultPipeline = new BABYLON.DefaultRenderingPipeline(
        "DefaultRenderingPipeline",
        true, // is HDR?
        scene,
        scene.cameras
    );
	
	
			
    if (defaultPipeline.isSupported) {
      
        defaultPipeline.samples = 8; 
       
        defaultPipeline.imageProcessingEnabled = true; 
        if (defaultPipeline.imageProcessingEnabled) {
            defaultPipeline.imageProcessing.contrast = 1; 
            defaultPipeline.imageProcessing.exposure = 1; 

		}}
		
		

		

			//CAMERA  
	
			var camdistance = $('#renderCanvas').data('camdistance');
			var camX = $('#renderCanvas').data('camerax');
			var camY = $('#renderCanvas').data('cameray');
			var camZ = $('#renderCanvas').data('cameraz');
			
            var camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, camdistance, new BABYLON.Vector3(camX, camY, camZ));
            //camera.attachControl(canvas, true);
			
			
			//LIGHTS
           const lighthemi = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(1, 1, 0));
			lighthemi.intensity = 1;	
			
			
var light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(-200, -10, 200), scene);
light.position = new BABYLON.Vector3(0, 150, -250);
		light.intensity = 3;			

			canvas.removeEventListener('mousewheel', camera._wheel);canvas.removeEventListener('DOMMouseScroll', camera._wheel);
			camera.inputs.attached.pointers.buttons = [0,1]; // disables right button
			camera.panningSensibility = 0; 
			camera.lowerRadiusLimit = camdistance;
			camera.upperRadiusLimit = camdistance;
			camera.minZ = 0;
			//camera.useAutoRotationBehavior = true;

			// Shadows
		
	var shadowGenerator = new BABYLON.ShadowGenerator(2048, light);
			
			
			
			
			/*
            var mesh = BABYLON.SceneLoader.ImportMeshAsync(null,"./3D/glTF/", meshname, scene, function (scene) { 
				
				 .then((result) => {
    result.meshes[1].position.x = 20;
    const myMesh1 = scene.getMeshByName("myMesh_1");
    myMesh1.rotation.y = Math.PI / 2;
});
				
				 var mesh = scene.meshes[0];

	shadowGenerator.addShadowCaster(scene.meshes[2])	
				
				
				
	shadowGenerator.useBlurExponentialShadowMap = true;
    shadowGenerator.useKernelBlur = true;
    shadowGenerator.blurKernel = 32;

			});
	*/			
				
			
		
					//GROUND
			var ground = BABYLON.Mesh.CreateGround("ground", 200, 200, 10, scene);

			// Colour the ground
        var material = new BABYLON.StandardMaterial(scene);
        material.alpha = .5;
        ground.material = material;
	ground.receiveShadows = true;
				
						
			
			
				//MESH  

			var meshname = $('#renderCanvas').data('meshname');
			BABYLON.SceneLoader.ImportMesh("","./3D/glTF/", meshname+".glb", scene, function (newMeshes) {
        // Set the target of the camera to the first imported mesh
        
				
				camera.target = getMeshByName(name);
		var name = newMeshes[0].name;

	  scene.registerBeforeRender(function () {
	        light.position = camera.position;
			scene.getMeshByName(name).rotation.y += 0.02;
	    });
    });

    
	
			

            return scene;
        };

        const scene = createScene(); //Call the createScene function
//scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
        // Register a render loop to repeatedly render the scene
        engine.runRenderLoop(function () {
			
                scene.render();
			
			
        });

        // Watch for browser/canvas resize events
        window.addEventListener("resize", function () {
                engine.resize();
        });
    </script>

   </body>

</html>

```

---

<div class="post-metadata">

**Author:** ![Raggar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raggar/32/20672_2.png) [@Raggar](https://forum.babylonjs.com/u/Raggar)\
**Post date:** [October 10, 2021, 4:54pm UTC](https://forum.babylonjs.com/t/cant-make-my-mesh-rotate/24459/2 "2021-10-10T16:54:31Z")

</div>

Exported meshes usually(always?) have rotationQuaternions.  
You can either null them out with mesh.rotationQuaternion = null and then use the .rotation property  
Or you can use the rotate function [Mesh | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/babylon.mesh#rotate)  
Or manually rotate the quaternion.

---

<div class="post-metadata">

**Author:** ![Brunozerouno](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brunozerouno/32/21051_2.png) [@Brunozerouno](https://forum.babylonjs.com/u/Brunozerouno)\
**Post date:** [October 10, 2021, 7:50pm UTC](https://forum.babylonjs.com/t/cant-make-my-mesh-rotate/24459/3 "2021-10-10T19:50:28Z")

</div>

I don’t know why but the mesh is still not rotating after adding:

```auto
scene.getMeshByName(name).rotationQuaternion = null;

```

---

<div class="post-metadata">

**Author:** ![Brunozerouno](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brunozerouno/32/21051_2.png) [@Brunozerouno](https://forum.babylonjs.com/u/Brunozerouno)\
**Post date:** [October 10, 2021, 7:54pm UTC](https://forum.babylonjs.com/t/cant-make-my-mesh-rotate/24459/4 "2021-10-10T19:54:26Z")

</div>

Thanks but after adding

```auto
scene.getMeshByName(name).rotationQuaternion = null;

```

it still doesn’t rotate.

---

<div class="post-metadata">

**Author:** ![Mekaboo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mekaboo/32/440_2.png) [@Mekaboo](https://forum.babylonjs.com/u/Mekaboo)\
**Post date:** [October 10, 2021, 8:05pm UTC](https://forum.babylonjs.com/t/cant-make-my-mesh-rotate/24459/5 "2021-10-10T20:05:26Z")

</div>

See if this helps:

myMesh1.rotate(BABYLON.Vector3.Up(), -Math.PI / 2);

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 10, 2021, 8:09pm UTC](https://forum.babylonjs.com/t/cant-make-my-mesh-rotate/24459/6 "2021-10-10T20:09:19Z")

</div>

A repro in the playground would help us catch it in no time.

---

<div class="post-metadata">

**Author:** ![Brunozerouno](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brunozerouno/32/21051_2.png) [@Brunozerouno](https://forum.babylonjs.com/u/Brunozerouno)\
**Post date:** [October 10, 2021, 8:51pm UTC](https://forum.babylonjs.com/t/cant-make-my-mesh-rotate/24459/7 "2021-10-10T20:51:19Z")

</div>

[https://playground.babylonjs.com/#Q5B2PU#1](https://playground.babylonjs.com/#Q5B2PU#1)

---

<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:** [October 10, 2021, 9:02pm UTC](https://forum.babylonjs.com/t/cant-make-my-mesh-rotate/24459/8 "2021-10-10T21:02:59Z")

</div>

It’s spinning now

By opening the console you would have seen your error.: getMeshByName(name). Scene was missing.  
Also the rotationQuaternion can be outside the loop registerBeforeRender  
And you can directly use newMeshes [0] rather than getMeshByName.

[https://playground.babylonjs.com/#Q5B2PU#3](https://playground.babylonjs.com/#Q5B2PU#3)
