Move layer by marker Name

Moderators: Disciple, zlovatt

Post Reply
z00story
Posts: 8
Joined: September 4th, 2008, 10:29 am

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!
z00story
Posts: 8
Joined: September 4th, 2008, 10:29 am

anyone? Beuller?
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

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.
z00story
Posts: 8
Joined: September 4th, 2008, 10:29 am

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 ?
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

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
z00story
Posts: 8
Joined: September 4th, 2008, 10:29 am

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
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

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.
Post Reply