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

if else troubles and issues.

New Here ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

 

var speed = 610; 
var bottomValue = 1150;
var topValue = -70;

var distance = bottomValue - topValue;

var time = distance / speed;

var currentTime = time % 2;

var currentPosition = linear(currentTime, 0, 1, topValue, bottomValue);

if (currentPosition >= bottomValue) {
currentPosition = topValue;}

[value[0], currentPosition];

 

the code is suposed to make the shapes go from the starting position then travels down to y1150 then teleports back up to -70 and repeats with a speed of 610 pixels per second, but the if else statement makes the shape motionless, how do i fix this or get around this?

TOPICS
Error or problem , Expressions , How to

Views

218

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
Community Expert ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

There are a lot of problems with your expresion. It will not change any values over time.

The linear(t, tMin, tMax, value1, value2) interpolation method requires a "t" value that changes over time.

 

You are using currentTime as the "t" value.  You have set the reserved word "time" as a variable and defined that variable as the distance between the top value and the bottom value divided by 650 (speed). This gives a number that does not change. currentTime = (1150 - (-70)) /610, and that equals 2, and the 2 never changes so the output of the linear expression is always value1 or Zero. 

 

The time required to complete the move is just the starting value for "tMin" and the ending value for "tMax." You don't even have to calculate the difference between the starting and ending value value1 + value2. Set those variables to -70 and 1150, and you have the move defined. No subtraction or calculations are necessary.

 

The expression needed to move the layer from -70 in y to 1150 in y in one second is as follows:

 

t = time - inPoint;
y = linear(t, 0, 1, -70, 1150;
[value[0], y]

 

You could also write the expression like this because Interpolation Methods can calculate arrays:

t = time - inPoint;
linear(t, 0, 1, [value[0], -70], [value[0], 1160])

 

If you want the animation to loop, you need to set up a formula that resets the value of "t" to zero every time one second passes. I can't write that in my head, so you'll have to wait until I can get to it or Dan Ebberts steps in.

 

When I have short animations that I want to loop, I trim the layer to the end of the animation, pre-compose moving all attributes to the new comp and trim the pre-comp to the layer length, then add time-remapping to the Pre-comp, go to the last TR keyframe which is after the layer plays, move back one frame, set a new TR keyframe using the diamond in the keyframe navigator, delete the last keyframe so there is an image displayed on the first and last TR keyframe. Then just add loopOut(), and the animation will loop forever.

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
Community Expert ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

LATEST

Maybe you were trying for something like this:

var spd = 610; 
var bottomValue = 1150;
var topValue = -70;

var distance = bottomValue - topValue;
var y = topValue + (time*spd)%distance;
[value[0],y]

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