Copy link to clipboard
Copied
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!
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
...Copy link to clipboard
Copied
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))
Copy link to clipboard
Copied
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!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now