LookAt with distance constraint

Moderators: Disciple, zlovatt

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

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

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
kennethbonde
Posts: 7
Joined: March 17th, 2008, 3:25 pm

Perfect Dan !

Can I donate a beer ?

>kenneth
Post Reply