Skip to main content
Known Participant
November 15, 2023
Answered

Manipulation of the Distance Between Two Nulls when a third Null moves closer or further away.

  • November 15, 2023
  • 12 replies
  • 1090 views

Dear Community, I have the following problem/goal:

 

When object #1 gets closer to object #2, the distance between #2 and #3 must be reduced. (Object #3 should, however, always retain its position)

 

 

The following solution is not satisfying, because although the position is manipulated, the movement is not always oriented to the center (where object number 3 is located):

 

var p1 = thisLayer.position;
var p2 = thisComp.layer("Effector").position;
var delta = sub(p1,p2);
var distance = length(delta);
linear(distance, 0, 250, [value[0],value[1]+100], [value[0],value[1]]);

 

Thank you in advance for your expertise.

This topic has been closed for replies.
Correct answer dfred23

It works!  Thanks a ton, dfred23

 

One additional question, please. It would be great to be able to determine an interaction radius. I.e. a certain distance between #1 and #2 ensures a certain distance between #2 and #3.


It sounds like you want to clamp the values. There's probably an easier way to do this, but try adjusting the clampDivisor value. The higher the value the closer to the target it will get:

 

clampDivisor = 2;
effector = thisComp.layer("Effector").position;
target = thisComp.layer("Target").position;
distance = length(value, effector);
clampTarget = target + div(sub(value, target), clampDivisor);
ease(distance, 0, 800, clampTarget, value);

 

12 replies

Inspiring
November 15, 2023

Instead of using the vector math could you just use a simple linear interpolation?

 

effector = thisComp.layer("Effector").position;
center = [thisComp.width/2, thisComp.height/2];
linear(effector[0], effector.valueAtTime(0)[0],center[0],center,value);
Known Participant
November 15, 2023

Thank you @dfred23

 

Your approach would be great if #1 would only move in the X-axis, like this:

 

 

The goal is to rotate object #1 around the circle. When #1 moves away from #2, #2 should return to its original position. However, it does not do this with this approach if #1 is moved along the Y-axis:

 

 

 

So I think the distance between #1, #2 and #3 has to be measured.

 

Thanks!

Mylenium
Legend
November 15, 2023

There's all manner of "targeting" expressions out there. Just look them up.

 

Mylenium

Known Participant
November 15, 2023

Now I'm even more confused.

 

Thanks!