# constraints on mesh rotation

## 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

##### Share on other sites

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}

##### 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.

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

##### Share on other sites
5 minutes ago, adam said:

Thank you!

## 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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×

×