LookAt with distance constraint

Moderators: Disciple, zlovatt

Post Reply
Posts: 7
Joined: March 17th, 2008, 3:25 pm

January 27th, 2010, 9:13 am

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

(13.22 KiB) Downloaded 792 times
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA

January 28th, 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.

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;
    targetVal = lookAt(position.valueAtTime(t),targetPos.valueAtTime(t));
    curVal = linear(inRangeCt,0,acquireFrames,refVal,targetVal);
    inRangeCt = 0;
Posts: 7
Joined: March 17th, 2008, 3:25 pm

January 28th, 2010, 1:05 pm

Perfect Dan !

Can I donate a beer ?

Post Reply