ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Continuous linear movement that starts and stops on a checkbox

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
James Ronan
Continuous linear movement that starts and stops on a checkbox
on Mar 13, 2019 at 9:12:30 am

Hey all

I've got an object continuously move along one axis at a rate of 5px per frame.

What I'd like to do is set up a check box that when checked, starts and stops the movement. Keeping the object in the same position until it's checked again.
So far any attempt I've had resets the objects position to 0 when checkbox is false;


var pos = 0;
var check = effect("Checkbox Control")("Checkbox");
var frames = timeToFrames(time,25)
var speed = 5;

for (var i = 0; i < (frames); i++){
if (check == 1){
pos += speed;
}
}

pos;


Any help would be awesome!

Thanks!


Return to posts index

Alex Printz
Re: Continuous linear movement that starts and stops on a checkbox
on Mar 13, 2019 at 1:56:24 pm

You were really close, you just need to check if the checkbox controller is active at that specific frame:

var pos = 0;
var check = effect("Checkbox Control")("Checkbox");
var frames = timeToFrames(time,25)
var speed = 5;

for (var i = 0; i < (frames); i++){
if (check.valueAtTime(framesToTime(i)) == 1){
pos += speed;
}
}

[pos,0];


Also, I think you can drop your timeToFrames FPS property (25), unless specific, the function will default to the comp framerate.

Alex Printz
Mograph Designer


Return to posts index

James Ronan
Re: Continuous linear movement that starts and stops on a checkbox
on Mar 14, 2019 at 3:10:37 pm

Ah thanks for the reply Alex! That makes more sense!

So it's still not working working for me unfortunately. It works in a text layer... I can see it counting up.

But when used on a position property, rotation etc. it still doesn't work and only shows the initial value written at the start.

Any idea why? Thanks again!!!

James


Return to posts index


Alex Printz
Re: Continuous linear movement that starts and stops on a checkbox
on Mar 15, 2019 at 2:41:17 pm

Are you sure that it is not working for you? I just copy+paste'd my code into a shapelayer's position and rotation, and it worked fine in both of those. Are you getting any sort of error?

Alex Printz
Mograph Designer


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]