Page 1 of 1

LookAt with distance constraint

Posted: January 27th, 2010, 9:13 am
by kennethbonde
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

Re: LookAt with distance constraint

Posted: January 28th, 2010, 12:16 pm
by Dan Ebberts
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.

Code: Select all

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

Re: LookAt with distance constraint

Posted: January 28th, 2010, 1:05 pm
by kennethbonde
Perfect Dan !

Can I donate a beer ?

>kenneth