Page 1 of 1

Move layer by marker Name

Posted: September 4th, 2008, 1:05 pm
by z00story
Hey I am trying to move a layer based on comp markers comment IDs, take a look at what I have so far:

Code: Select all

snapSpeed = .2
m = thisComp.marker;
thePos = [transform.position[0], transform.position[1]];

//Configuration Locations
location = [[1541,824],[2685,210]];

mNum = m.nearestKey(time).comment;

//Movement Code
if (m.numKeys > 0) {
	ease_in(time, m.key(mNum).time,m.key(mNum).time+snapSpeed,thePos,location[mNum]);
	thePos = location[mNum];
} else {
	thePos;
}
My problem is with the mNum variable. I need it to pull the comment from the marker that it hits and stay with that comment until it hits the next marker. By using nearestKey(time) it switches to the next marker too early, when the time is closer to the next marker.

So my idea is my team can place markers like "0" to have the object go to the coords for 0, "1" goes to coords for 1 and so on.

Help much appreciated!

Re: Move layer by marker Name

Posted: September 4th, 2008, 2:18 pm
by z00story
anyone? Beuller?

Re: Move layer by marker Name

Posted: September 4th, 2008, 3:18 pm
by kobyg
Try changing this:
mNum = m.nearestKey(time).comment;

to this:
ind = m.nearestKey(time).index;
if (m.nearestKey(time).time > time){
ind--;}
ind = ind<1 ? 1 : ind;
mNum = m.key(ind).comment;

Koby.

Re: Move layer by marker Name

Posted: September 4th, 2008, 7:50 pm
by z00story
Thanks, I updated the script to this:

Code: Select all

snapSpeed = .2
location = [[644,858],[2685,210],[2098,834]];
m = thisComp.marker;

//FIND THE CURRENT MARKER
if (m.numKeys > 0) {
	ind = m.nearestKey(time).index;
		if (m.nearestKey(time).time > time)	{
			ind--;
			
		}
		
		ind = ind<1 ? 1 : ind;	
		mNum = m.key(ind).comment;
		
endTime = m.key(mNum).time+snapSpeed

//ANIMATE TO THE RIGHT POSITION
  	 ease_in(time, m.key(mNum).time,endTime,position,location[mNum]);

//Update position to the new position????
} 
Now my last problem is, each time it hits a new marker, it quickly tosses the layer back to its original position then animates to the new position.

Is there a way to capture the new position of the layer after the ease in and set that as the new layer.position ?

Re: Move layer by marker Name

Posted: September 4th, 2008, 9:02 pm
by Dan Ebberts
There's no way to have the expression remember where you were, but what you can do, once you get the index for the most recent marker, is decrement that to get the marker before that. That would give you the comment you'd use to index into your array for the start location for your ease().

So basically your expression needs to figure out the start location and end location for the ease at each frame. You just need to watch out for the case where you haven't reached the second marker yet.

Dan

Re: Move layer by marker Name

Posted: September 4th, 2008, 9:46 pm
by z00story
Dan Ebberts wrote:There's no way to have the expression remember where you were, but what you can do, once you get the index for the most recent marker, is decrement that to get the marker before that. That would give you the comment you'd use to index into your array for the start location for your ease().

So basically your expression needs to figure out the start location and end location for the ease at each frame. You just need to watch out for the case where you haven't reached the second marker yet.

Dan

Is it possible to get a written example? I'm a wee bit confused!

Thanks

Re: Move layer by marker Name

Posted: September 4th, 2008, 10:37 pm
by kobyg
What you should do, just like Dan wrote, is something like that:
(I assumed that before you reach the first comment, you wanted the position to be the original position of the layer)

Code: Select all

snapSpeed = .2
location = [[644,858],[2685,210],[2098,834]];
m = thisComp.marker;

//FIND THE CURRENT MARKER
if (m.numKeys > 0) {
   ind = m.nearestKey(time).index;
      if (m.nearestKey(time).time > time)   {
         ind--;
         
      }
      
      ind = ind<1 ? 1 : ind;   
      mNum = m.key(ind).comment;
      prev_ind = ind-1;
      if (prev_ind<1)
            prev_position =position;
      else{
            prev_mNum = m.key(prev_ind).comment;
            prev_position = location[prev_mNum];
      }
      
endTime = m.key(mNum).time+snapSpeed

//ANIMATE TO THE RIGHT POSITION
      ease_in(time, m.key(mNum).time,endTime,prev_position,location[mNum]);

//Update position to the new position????
}
Koby.