Rodrix3 Posted May 8, 2018 Share Posted May 8, 2018 Very simple. I have a mesh and I would like to rotate it by setting the current rotation.x to +=0.05. I am actually looking to rotate an object in about 10 degrees on x axis, from initial position. I tried mesh._rotation.x = 0.05 and the result is not what I want. This rotates the mesh 0.05 on EVERY frame. This means that I get an additional rotation per frame render. Instead I want the rotation to be SET to 0.05 (not incremented). I need to set the rotation in absolute terms, not relative. How can this simple thing be done? Thanks so much in advance! P.S: I even tried: mesh.rotate(BABYLON.Axis.X, 0.1, BABYLON.Space.WORLD); ..but again this rotates 0.1 on EVERY frame and rotation is accumulated. I want to set the rotation to the absolute number of 0.1 (not an incremental relative number) Quote Link to comment Share on other sites More sharing options...
Magilla Posted May 8, 2018 Share Posted May 8, 2018 Head over to https://playground.babylonjs.com/ and at the top right, change from "Basic Scene" to "Rotation and Scaling". There, you'll see the code required to do rotations the way you want. The rotations are not based on 360 degrees. 360 degrees is actually 2xPi (or about 6.28). To rotate by n degrees, you'd want to rotate by a value of (2 * Math.PI) / 360 * n. Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 8, 2018 Share Posted May 8, 2018 5 hours ago, Rodrix3 said: mesh._rotation.x = 0.05 Why the underscore? mesh.rotation.x = 0.05 should do want you need. Quote Link to comment Share on other sites More sharing options...
Rodrix3 Posted May 8, 2018 Author Share Posted May 8, 2018 Thanks @Magilla and @JohnK however this does not solve my problem. The two functions rotate the object every time. If I have a loop: { mesh.rotation.x = 0.05; } ..will rotate the mesh on every loop frame. I don't want that. I want to SET the rotation INSIDE the loop (not at the creation of the scene) to specific rotation coordinates. How can I do that? Thanks! Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 8, 2018 Share Posted May 8, 2018 I am missing something when you SET any rotation INSIDE a loop the rotation will be called for each frame of the loop by definition of a loop. Please give a simple playground with comments to show what you want to happen and where. Quote Link to comment Share on other sites More sharing options...
jerome Posted May 8, 2018 Share Posted May 8, 2018 wrong setting a rotation value doesn't add this value each frame. Quote Link to comment Share on other sites More sharing options...
Magilla Posted May 9, 2018 Share Posted May 9, 2018 20 hours ago, Rodrix3 said: I have a mesh and I would like to rotate it by setting the current rotation.x to +=0.05. Are you using rotation.x = 0.05 or rotation.x += 0.05 in your code? rotation.x += 0.05 is the same as saying rotation.x = rotation.x + 0.05 which will DEFINITELY cause your mesh to spin every frame, because it will change (add 0.05 to) the value of rotation.x every time the loop goes through. To set the value so it doesn't change, use rotation.x = 0.05. Quote Link to comment Share on other sites More sharing options...
Rodrix3 Posted May 10, 2018 Author Share Posted May 10, 2018 @jerome, @Magilla, I am using the Chrome's console. And on the console rotation = 0.05 seems to have the effect of rotation += 0.05. Not sure why.. very weird. I will try adding the code on the render loop to see if it makes any difference. Any insights? Thanks so much! Quote Link to comment Share on other sites More sharing options...
Magilla Posted May 10, 2018 Share Posted May 10, 2018 Until you show us some code, we have two options: Show you it working correctly (see my first post) Make wild guesses (see the rest of the thread) The behaviour you describe does not make sense in my experience of the system, so unless someone has seen it and solved it previously, I don't know that there's a lot more we can do. Quote Link to comment Share on other sites More sharing options...
Rodrix3 Posted May 10, 2018 Author Share Posted May 10, 2018 Yes, of course! I understand. Let me do a full test on my end and include the code on the render loop and get back to you guys. Thanks again for your time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.