DezOnlyOne Posted August 9, 2016 Share Posted August 9, 2016 is there a simple way to limit the amount of rotation of a mesh? I have a throttle in my project and I have it setup so that I can click and drag it to rotate the lever on the x axis(Thanks to Wingnut and others in this forum). I want to limit the amount that it can be rotated no matter how much the drag, but I am getting odd results. Is there a way that I can use a clamp to lock the rotation into a certain angle? PS... to move the throttle, you click and drag from the cylinder objects on the left or right http://www.babylonjs-playground.com/#2DHIAE#0 Thanks in advance Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 10, 2016 Share Posted August 10, 2016 Hello why not jsut adding a function to check rotation.x after setting it up? Like: if rotation.x > Math.PI { rotation.x = Math.PI} Quote Link to comment Share on other sites More sharing options...
DezOnlyOne Posted August 10, 2016 Author Share Posted August 10, 2016 Thanks for the suggestion. I did try that. he odd results are what I was talking about. There is a flickering and the rotation is reset when you click on the throttle again. http://www.babylonjs-playground.com/#2DHIAE#2 Lines 142-161 var rotCfg = { min: -3, max: 0 } if (currentMesh.name === 'throttle_left_do') { if (throttleLeft.rotation.x < rotCfg.min) { throttleLeft.rotation.x = rotCfg.min; onPointerUp(); } else if (throttleLeft.rotation.x > rotCfg.max) { throttleLeft.rotation.x = rotCfg.max; onPointerUp(); } else { var newRotation = rotationInit - dragDiff.y / 10; throttleLeft.rotation.x = -newRotation; } } if (currentMesh.name === 'throttle_right_do') { if (throttleRight.rotation.x < rotCfg.min) { throttleRight.rotation.x = rotCfg.min; onPointerUp(); } else if (throttleRight.rotation.x > rotCfg.max) { throttleRight.rotation.x = rotCfg.max; onPointerUp(); } else { var newRotation = rotationInit - dragDiff.y / 10; throttleRight.rotation.x = -newRotation; } } Quote Link to comment Share on other sites More sharing options...
adam Posted August 10, 2016 Share Posted August 10, 2016 http://www.babylonjs-playground.com/#2DHIAE#3 Quote Link to comment Share on other sites More sharing options...
DezOnlyOne Posted August 10, 2016 Author Share Posted August 10, 2016 5 minutes ago, adam said: http://www.babylonjs-playground.com/#2DHIAE#3 Thank you! 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.