ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Two wiggles in the same camera position

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Robson TehacyńskiTwo wiggles in the same camera position
by on Aug 29, 2014 at 9:01:47 am

Hi there!

I have a huge problem, which i guess you can help me with, guys. So here it is:

I'm using a wiggle expression in camera's position:

startFrame = framesToTime(492); stopFrame = framesToTime(670); easeOver = framesToTime(20); freq = 0.5; amp = 35; if((time >= startFrame)&&(time < stopFrame)){ if(time < startFrame + easeOver) linear(time, startFrame, startFrame + easeOver, value, wiggle(freq,amp)); if(time >= stopFrame - easeOver) linear(time, stopFrame - easeOver, stopFrame, wiggle(freq,amp), value); else wiggle(freq,amp); } else value

which basically wiggles the camera from frame 492 to frame 670 (with a little blending at initial and final frames). I'd like to use the same expression for the same camera and position, which will start at frame 860 and end at 920, but... When i use the same expression, just copy it under the existing one- it basically uses the second one without the first one.

So my question is- How can i force them both to work for me?


Return to posts index

Walter SoykaRe: Two wiggles in the same camera position
by on Aug 29, 2014 at 5:57:32 pm

Both expressions are always being evaluated, and the second one is "overwriting" the value calculated in the first. You'd need to wrap the second condition into the else of the first to fix this.

Personally, I hate using absolute frame references in expressions. Instead, I like to use layer markers.

I've written some expression functions for getting information about layer markers relative to time -- I'll do a proper write-up and blog entry soon -- but in the meantime, here's some code that will let you do any number of camera shakes on the same layer, setting the start and times with matching pairs of layer markers.

// expression for adding camera wiggle in between layer markers
easeOver = framesToTime(20);
freq = 0.5;
amp = 35;

if (inBetweenMarkerPair()) {
startFrame = getLastMarkerTime();
stopFrame = getNextMarkerTime();
if((time >= startFrame)&&(time < stopFrame)) {
if(time < startFrame + easeOver) linear(time, startFrame, startFrame + easeOver, value, wiggle(freq,amp));
if(time >= stopFrame - easeOver) linear(time, stopFrame - easeOver, stopFrame, wiggle(freq,amp), value); else wiggle(freq,amp);
} else value;

} else value;








/* ********************************************************************************************************
After Effects expression functions by Walter Soyka (Twitter @keenlive, blog at http://www.renderbreak.com)

Following, a set of functions related to layer markers:

function getLastMarkerTime(refLayer, refTime) returns a float for the time of last (or current) marker, or null when a meaningful value is N/A.
function getLastMarkerIndex(refLayer, refTime) retrusn an integer for the index of the last (or current) marker, or null when a meaningful value is N/A.
function getNextMarkerTime(refLayer, refTime) returns a float for the time of the next marker, or null when a meaningful value is N/A.
function getNextMarkerIndex(refLayer, refTime) returns an integer for the index of the last marker, or null when a meaningful value is N/A.
function inBetweenMarkerPair(refLayer, refTime) returns a boolean; true when in beween an odd-numbered and an even-numbered marker, false all other times

In all cases, refLayer and refTime are optional. If you wish to examine the markers on another layer or at another time, pass them here.
If refLayer or refTime is not provided, "thisLayer" and "time" are used, respectively.


******************************************************************************************************** */

function getLastMarkerTime(refLayer, refTime) {
if (refLayer == null) refLayer = thisLayer;
if (refTime == null) refTime = time;
if (refLayer.marker.numKeys > 0) {
n = refLayer.marker.nearestKey(refTime).index;
if (refLayer.marker.key(n).time > refTime) n--;
if (n < 1) { return null; } else { return refLayer.marker.key(n).time; }
} else return null;
}

function getLastMarkerIndex(refLayer, refTime) {
if (refLayer == null) refLayer = thisLayer;
if (refTime == null) refTime = time;
if (refLayer.marker.numKeys > 0) {
n = refLayer.marker.nearestKey(time).index;
if (refLayer.marker.key(n).time > refTime) n--;
if (n < 1) { return null; } else { return n; }
} else return null;
}

function getNextMarkerTime(refLayer, refTime) {
if (refLayer == null) refLayer = thisLayer;
if (refTime == null) refTime = time;
if (refLayer.marker.numKeys > 0) {
n = refLayer.marker.nearestKey(refTime).index;
if (refLayer.marker.key(n).time <= refTime) n++;
if (n > refLayer.marker.numKeys) { return null; } else { return refLayer.marker.key(n).time; }
} else return null;
}

function getNextMarkerIndex(refLayer, refTime) {
if (refLayer == null) refLayer = thisLayer;
if (refTime == null) refTime = time;
if (refLayer.marker.numKeys > 0) {
n = refLayer.marker.nearestKey(refTime).index;
if (refLayer.marker.key(n).time <= refTime) n++;
if (n > refLayer.marker.numKeys) { return null; } else { return n; }
} else return null;
}

function inBetweenMarkerPair(refLayer, refTime) {
if (refLayer == null) refLayer = thisLayer;
if (refTime == null) refTime = time;
l = getLastMarkerIndex(refLayer, refTime);
n = getNextMarkerIndex(refLayer,refTime);
if ((l!= null) && (n != null)){
if ((l%2 != 0) && (n%2 == 0)) { return true; } else { return false;}
} else return false;
}


Walter Soyka
Designer & Mad Scientist at Keen Live [link]
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
@keenlive [twitter]   |   RenderBreak [blog]   |   Profile [LinkedIn]


Return to posts index

Robson TehacyńskiRe: Two wiggles in the same camera position
by on Aug 30, 2014 at 9:12:32 pm

Sorry for being so dumb, your first script isn't working for me... Here is the error massage:

"Function inBetweenMarkerPair is undefined. Expression disabled." Putting the marker names in the brackets does not help in this case.

What am i doing wrong?


Return to posts index


Walter SoykaRe: Two wiggles in the same camera position
by on Aug 30, 2014 at 11:20:18 pm

Are you sure you copied and pasted the whole thing? I just tried copying and pasting from my post in the forum here, and it worked.

Walter Soyka
Designer & Mad Scientist at Keen Live [link]
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
@keenlive [twitter]   |   RenderBreak [blog]   |   Profile [LinkedIn]


Return to posts index

Philipp SniechotaRe: Two wiggles in the same camera position
by on Aug 31, 2014 at 12:18:32 am


if(time > framesToTime(800)) {
startFrame = framesToTime(860);
stopFrame = framesToTime(920);
} else {
startFrame = framesToTime(492);
stopFrame = framesToTime(670);
}

easeOver = framesToTime(20);
freq = 0.5;
amp = 35;
if ((time >= startFrame) && (time < stopFrame)) {
if (time < startFrame + easeOver) linear(time, startFrame, startFrame + easeOver, value, wiggle(freq, amp));
if (time >= stopFrame - easeOver) linear(time, stopFrame - easeOver, stopFrame, wiggle(freq, amp), value);
else wiggle(freq, amp);
} else value


This should do the trick. The if-else on the top can be extended and just changes the values of the two variables over time.


Return to posts index

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