Expressions/Scripts/Presets

Moderators: Disciple, zlovatt

 
kennethbonde
Topic Author
Posts: 7
Joined: Mon Mar 17, 2008 3:25 pm

LookAt with distance constraint

Wed Jan 27, 2010 9:13 am

Hi
I want to create an expression that will orient a layer towards a null, but only if the null is within a certain distance.

I have done most of the expression, but if the null is outside the range I want the layer to remember the last null position when within range.

Is it possible to do some kind of smooth layer orient, so the layer won't jump when the null re-enters somewhere else in 3D-space ?

Any help appreciated - CS4 project attached

>kenneth
Attachments
lookAt_expression_cs4_v3.aep.zip
(13.22 KiB) Downloaded 683 times
 
Dan Ebberts
Posts: 318
Joined: Sat Jun 26, 2004 10:01 am
Location: Folsom, CA
Contact:

Re: LookAt with distance constraint

Thu Jan 28, 2010 12:16 pm

This is one of those cases where, to do it right, you need to recreate everything that's happend since the layer's In Point. That means it slows down as you get farther into the comp. This is set up so that when the target moves within range, it is acquired in 3 frames. Having the acquire time be dependent on how far the tracker needs to turn would be trickier. Anyway, play around with it and see if it does what you need.

targetPos = thisComp.layer("traget_wiggle_position_and_opacity").transform.position;
range = thisComp.layer("range control").effect("range")("Slider");
acquireFrames = 3; // number of frames to acquire target
inRangeCt = 0;
curVal = lookAt(position.valueAtTime(inPoint),targetPos.valueAtTime(inPoint));
refVal = curVal;
for (f = timeToFrames(inPoint); f < timeToFrames(); f++){
  t = framesToTime(f)
  d = length(targetPos.valueAtTime(t),position.valueAtTime(t));
  if (d < range){
    if (inRangeCt == 0) refVal = curVal;
    inRangeCt++;
    targetVal = lookAt(position.valueAtTime(t),targetPos.valueAtTime(t));
    curVal = linear(inRangeCt,0,acquireFrames,refVal,targetVal);
  }else{
    inRangeCt = 0;
  }
}
curVal


Dan
 
kennethbonde
Topic Author
Posts: 7
Joined: Mon Mar 17, 2008 3:25 pm

Re: LookAt with distance constraint

Thu Jan 28, 2010 1:05 pm

Perfect Dan !

Can I donate a beer ?

>kenneth

Who is online

Users browsing this forum: No registered users and 1 guest