Expression: Ограничение дистанции

Применяется для параметра Position. 2D.

centre=thisComp.layer(“Centre”);
radius = 512; // Максимальная дистанция
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]

3D.

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