Copy link to clipboard
Copied
Hi, I'm actually working on simulations of movements and I'd like to make an expression to set position and rotation in function of time . my functions are :
position : X(t)= 15(cm/s)* t (s)
rotation : F(t)= -5(rad/s) *t (s)
Thanks in advance
Copy link to clipboard
Copied
Let's tackle your position expression first: position : X(t)= 15(cm/s)* t (s)
Position is an array and it looks like this: [x, y, z]
The values are x = [0], y = [1], and z = [2]
Time is defined by the word "time"
distance is measured in pixels not in centimeters.
If you want to control the position of x you must define x as a formula multiplying the initial value by time and a number of pixels you want it to move over a given amount of time. The easiest way to do this is to define the number of pixels, divide time into frames, then multiply the existing value of x by the pixels per frame.
The expression would look like this:
x = value[0];
y = value[1];
s = 2; // speed in pixels per frame
m = time/thisComp.frameDuration;
newx = x + (m * s);
[newx, y]
If you need the movement to exist on a 3D layer then add z = value[2]; and change the last line to [x, y, z]
Adjust the value of s to match your composition. If you want the layer to move in the other direction change the plus to a - sign for the calculation newx.
Now let's look at your rotation expression: rotation : F(t)= -5(rad/s) *t (s)
You've almost got it except that rotation is measured in degrees and you'll want to set up your expression to rotation speed in º per frame. There is no array for rotation so the language is a little easier.
The expression would look like this:
r = value;
s = .5 // degrees per frame
m = time/thisComp.frameDuration;
newr = r - (m * s);
Same deal here. Adjust the value of s to get the speed you want and change the minus sign to a plus in the newr calculation to change direction. Both allow you to set an initial value for the property or even additional keyframes if needed. That's why I used the value statement.
Hope this helps. I'd suggest reading the expression guide in the help files. Once you get a handle on the language the math is fairly easy.