Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Limit Rotation Expression

Community Beginner ,
Jan 22, 2016 Jan 22, 2016

Hi all. A (hopefully) quick question. Can anybody please advise on a basic expression to limit the rotation of an object when rotated manually. For example, so it can only move between 0-360, and no further in either direction?

Thanks in advance or any help!

TOPICS
Expressions
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jan 22, 2016 Jan 22, 2016

You can use the Math.min() and Math.max() functions to keep the value within a given range.  Bear in mind this won't limit the underlying pre-expression value, only the final value that is applied to the rotation.  The object will stop rotating when it reaches the upper or lower bound, but the value you are providing as input will not itself be constrained, if that is what you are hoping for.  If you crank it well beyond either limit, then you'll have to crank it all the way back to the useable

...
Translate
Advocate ,
Jan 22, 2016 Jan 22, 2016

You can use the Math.min() and Math.max() functions to keep the value within a given range.  Bear in mind this won't limit the underlying pre-expression value, only the final value that is applied to the rotation.  The object will stop rotating when it reaches the upper or lower bound, but the value you are providing as input will not itself be constrained, if that is what you are hoping for.  If you crank it well beyond either limit, then you'll have to crank it all the way back to the useable range or reset the value numerically, kind of like if a dimmer switch kept turning even after the light was at its max brightness, and reversing it didn't start dimming again until you undid all those extra revolutions.

Here's the expression:

minValue = 0;

maxValue = 360;

Math.max(minValue, Math.min(maxValue, value))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2016 Jan 23, 2016
LATEST

Thank you so much for this quick response to my question. It's exactly what I was looking for and it's very kind of you to take the time to explain everything in detail. Much appreciated, thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines