-
Move a layer according to its own location
Hi I would like to move a layer according to its own location.
Here is an example with its current location :
[transform.position[0] + 100 , transform.position[1]]
According to time, the layer doesn’t move because I cannot read the red value of each position axis.
Here is an example with its previous location :
x = thisComp.layer(index).transform.position.valueAtTime(time-1/25)[0] ;
y = thisComp.layer(index).transform.position.valueAtTime(time-1/25)[1] ;
[x+100, y]Again, the thing is that After Effects seems to read the blue (manual) values instead of the red (scripted) ones.
Is there any way to read the real position (red) instead of the blue one ?
The reason why I need to read the location of the current layer is because I want this layer to move according to the location of some other layers so that each react independantly.
If I want each layer to spread, I just have to make each layer move away from its closest neighboor :
NbLayers = comp(“Repartition”).numLayers ;
seedRandom(0, timeless = true) ;if (time == 0){
X_Pos = random(1920) ;
Y_Pos = random(1080) ;
}else{
X_Pos = thisComp.layer(index).transform.position.valueAtTime(time-1/25)[0] ;
Y_Pos = thisComp.layer(index).transform.position.valueAtTime(time-1/25)[1] ;
}ModuleTest = 1920 ;
Module = 1920 ;// We look for the closest layer
for (i = 1; i < NbLayers ; i++){
if(i != index){
// We don’t consider the current layer.
X_Calc = thisComp.layer(i).transform.position.value[0] ;
Y_Calc = thisComp.layer(i).transform.position.value[1] ;
ModuleTest = Math.sqrt((X_Pos-X_Calc)*(X_Pos-X_Calc)+(Y_Pos-Y_Calc)*(Y_Pos-Y_Calc)) ;
if(ModuleTest < Module){
// We found a layer that is closer than the previous one
// We keep its relative position
Module = ModuleTest ;
Argument = Math.atan2(Y_Pos – Y_Calc, X_Pos – X_Calc) ;
}
}
}// Let’s move away from this layer
ArgumentDep = Argument ;
X_Dep = Math.cos(ArgumentDep) ;
Y_Dep = Math.sin(ArgumentDep) ;[X_Pos + X_Dep , Y_Pos + Y_Dep]
(Of course I will limit the movement of each layer to the area of the comp (1920×1080 for instance) which is not a big deal.)
<div>Anyway I cannot figure this out and I have not found any clue in the forum. Please could you give me some ways to fix this ?
</div>