Limit the distance between two layers
With this expression, you can limit the distance between two layers, so that the distance does not exceed the specified value. Applies to the Position parameter.
For 2D-layers:
centre=thisComp.layer("Centre");
radius = 512; // Maximum distance
x0=value[0]-centre.transform.position[0];
y0=value[1]-centre.transform.position[1];
distance0 = Math.sqrt(x0*x0+y0*y0);
distance = Math.min(distance0,radius);
if (distance0>radius){
distance_mult = distance/distance0;
}else{
distance_mult = 1
}
x=centre.transform.position[0]+distance_mult*x0;
y=centre.transform.position[1]+distance_mult*y0;
[x,y]
For 3D-layers:
centre=thisComp.layer("Orbit"); radius = 505; x0=value[0]-centre.transform.position[0]; y0=value[1]-centre.transform.position[1]; z0=value[2]-centre.transform.position[2]; distance0 = Math.sqrt(x0*x0+y0*y0+z0*z0); distance = Math.min(distance0,radius); if (distance0>radius){ distance_mult = distance/distance0; }else{ distance_mult = 1 } x=centre.transform.position[0]+distance_mult*x0; y=centre.transform.position[1]+distance_mult*y0; z=centre.transform.position[2]+distance_mult*z0; [x,y,z]
Recommended Posts