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

Rotate the Shortest Direction?

New Here ,
Dec 08, 2022 Dec 08, 2022

Copy link to clipboard

Copied

Hi,

Trying to slider ease between 2 rotation values, what do I need to do to this script to make the 2D layer always rotate the shortest direction?

 

var total = 0, totalWeight = 0, remWeight = 0;
var rot  = thisComp.layer("Target").transform.rotation);
if (hasParent) rot = parent.rotation;
var fade = effect("Slider Control")("Slider");
total += fade*pos;
totalWeight += fade;
remWeight = 1 - totalWeight;
totalWeight==0 ? value : linear(remWeight,total/totalWeight,value);

 

TOPICS
Expressions , Scripting

Views

478

Translate

Translate

Report

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
LEGEND ,
Dec 08, 2022 Dec 08, 2022

Copy link to clipboard

Copied

You need to provide the full code, not truncated snippets. Where is the pos variable even defined? What role does the fade even play? And your code does not make any determination about the actual rotation value since it doesn't accumulate it in a loop, so this is pretty much never going to work. You can't figure such stuff out based on static values. When objects move, you'll just flip-flop from value to value. This code is basically useless for what you actualyl seem to want. It appears you merely copy & pasted it from somewhere without understanding any of the specifics.

 

Mylenium

Votes

Translate

Translate

Report

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
New Here ,
Dec 08, 2022 Dec 08, 2022

Copy link to clipboard

Copied

Here is the code adjusted, the bottom is basic weighting Maths it's pretty obvious what the Slider is for, but have commented so you understand. Rot for Pos is just a typo (but also pretty obvious would imagine for someone able to answer this :)).

 

// On Rotation
var total = 0, totalWeight = 0, remWeight = 0;
var rot  = thisComp.layer("Target").transform.rotation);
if (hasParent) rot = parent.rotation;
var fade = effect("Slider Control")("Slider");  // Slider is 0 to 1
total += fade*rot;
totalWeight += fade;
remWeight = 1 - totalWeight;
totalWeight==0 ? value : linear(remWeight,total/totalWeight,value);

Votes

Translate

Translate

Report

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
LEGEND ,
Dec 08, 2022 Dec 08, 2022

Copy link to clipboard

Copied

There's no real math anywhere. You're just arbitrarily increasing/ checking the values, so what exactly are you trying to do here? What is the reference point for the rotations? and again, unless you actually check and integratze the values in a loop, this won't do anything. In order to ease from A to B you need to have some differences in the values, not just linearly accumulate them.

 

Mylenium

Votes

Translate

Translate

Report

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
New Here ,
Dec 08, 2022 Dec 08, 2022

Copy link to clipboard

Copied

Hi,

How can you ease between 2 values the shortest way possible i.e. ObjA is at 2 degrees and ObjB is at 350degrees, how do you make ObjA rotate 2,10,359,358... etc. rather than 2,3,4,5,6.... The code below weights between 2 values: Value A when Slider is 0, Value B when Slider is 1. Something I can't figure needs to be added to make it Rotate forwards or backwards depending on which is shortest way:

 

// On Rotation
var total = 0, totalWeight = 0, remWeight = 0;
var rot  = thisComp.layer("Target").transform.rotation);
if (hasParent) rot = parent.rotation;
var fade = effect("Slider Control")("Slider");  // Slider is 0 to 1
total += fade*rot;
totalWeight += fade;
remWeight = 1 - totalWeight;
totalWeight==0 ? value : linear(remWeight,total/totalWeight,value);

 

Votes

Translate

Translate

Report

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
LEGEND ,
Dec 08, 2022 Dec 08, 2022

Copy link to clipboard

Copied

LATEST

You have all the answers already. You need to intregrate the values in a loop or else you have no way of knowing what the previous rotation values even were. Refer to Dan's article about the whys and hows:

 

http://www.motionscript.com/articles/speed-control.html

 

Mylenium

Votes

Translate

Translate

Report

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