d13 Posted November 24, 2017 Share Posted November 24, 2017 Hi Everyone! I'm trying to figure out how to do the following: 1. Tilt a sphere about 20 degrees on it's z axis. 2. Then spin the sphere around its tilted axis. The code I've been using up till looks something like this: When I create the mesh, I set up its z rotation like this: mesh.rotation.z = tiltValue * 180 / Math.PI; This does give me the axis that I need. Then I've been trying to spin the sphere around that tilted axis in the game loop, like this: mesh.rotation.y -= rotationValue But, this causes the mesh to wobble around the y and z a axis instead of spinning on the tilted y axis. That seems to make sense, but I don't know how to get the effect I need. Can anyone help? I've tried some of the code from this older thread Specifically this bit: mesh.rotate(BABYLON.Axis.z, 1, BABYLON.Space.LOCAL) ... but this throws an error: TypeError: t is undefined babylon.js:7:6425 I don't know if I'm on the right track or not, but any help will be much appreciated! Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 24, 2017 Share Posted November 24, 2017 Hi d13. I used about the same method as you... but it worked. https://www.babylonjs-playground.com/#012I9K#2 *shrug* My "local" isn't all-caps, just the first letter. Not sure if that is the issue. Update: Oh, when I change my .Z to .z, I get the same error as you. https://www.babylonjs-playground.com/#012I9K#3 I bet your "z" should be capitalized. weird. BitOfGold 1 Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted November 24, 2017 Share Posted November 24, 2017 If you use Quaternions, you can multiply rotations. Feel free to copy from my code:http://www.bitofgold.com/solarsystem/ Like this: Setup: mesh.baseRotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(0.0, 0.0, 20.0 * Math.PI / 180, 0.0)); mesh.rotationQuaternion = new BABYLON.Quaternion(); ... at every frame: mesh.rotationQuaternion.copyFrom(mesh.baseRotationQuaternion); mesh.rotationQuaternion.multiplyInPlace(BABYLON.Quaternion.RotationYawPitchRoll(alpha, 0.0, 0.0)); Wingnut 1 Quote Link to comment Share on other sites More sharing options...
d13 Posted November 24, 2017 Author Share Posted November 24, 2017 Awesomeness! Thank you Mr Wingnut, Sir, it works beautifully 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.