Skip to main content
electricpalmtrees
Known Participant
January 12, 2025
Question

Expression >> Attract a layer to a null object (pos) >> Adding a slider

  • January 12, 2025
  • 2 replies
  • 625 views

Hi all,

This is the attract layer to null object position  expression

thisComp.layer("YourNullObjectName").position;

 

The trouble is when added it's an instant snap to the destination null object. Is there anexpression i can add or alter this, so i can highlight a number / strong of the attractor and then expression pick whip this to a slider control? Much in the same way we do to the wiggle expression to use velocity to turn it on and off.

 

I'm looking to be able to use a 0 to 100% method with keyframes on a slider controller. So i can then add velocity and really chosen how to craft the animation to suit.

 

Over to you good people:)

Graham

 

 

2 replies

Mylenium
Legend
January 12, 2025

Could be as simple as this:

 

aRef=thisComp.layer("Attractor");
aPos=aRef.transform.position;
aForce=aRef.effect("Whatever")(Slider);

sPos=thisLayer.transform.position;

X=linear(aForce,0,100,sPos[0],aPos[0]);
Y=linear(aForce,0,100,sPos[1],aPos[1]);

[X,Y]

 

Mylenium

 

 

electricpalmtrees
Known Participant
January 12, 2025

cool Mylenium

couple of things i'm in 3D space so could you edit for x,y,z please.

 

also and fogive my lack of knowing please, what do i add into the "whatever" is that pick whipped to the slider i choose to use? example if my slider is called object_1138 then that line should be:

aForce=aRef.effect(object_1138) (Slider); correct?

 

electricpalmtrees
Known Participant
January 12, 2025

recent to the above i have worked out that i can add an expression to a layer object and then use 2 nulls to move using a slider. this one..

linear(pick-whip-slider-value-here, 0, 100, pick-whip-null-1-position-here, pick-whip-null-2-position-here)

 

the thing is i have hundreds of objects already, so i’m trying to work out if i can get the slider setup into this starting point ( “thisComp.layer(“YourNullObjectName”).position;” ) , so i’d only have the object layer and 1 null, which would be better and more manageable.

 

love to hear your views and feedback please