Jump to content

constraints on mesh rotation


DezOnlyOne
 Share

Recommended Posts

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

Link to comment
Share on other sites

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;
	}
}

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...