-
Make a layer always point away from another layer
I wrote an expression to have the square always point away from the circle, and the circle to always point to the layer.

However, I think I took the brute force route and feel like there is a smarter way to accomplish this effect.
My expression is a series of if/else statements that first figures out which quadrant of the comp the circle is in (relative to the square), and uses that information to calculate the angles.
Is there a way to not calculate what quadrant you’re in, and instead just look at the positions of the objects relative to the comp and calculate the angles?
I’d like to eventually set this up in Xpresso in C4D, which is why I was hoping to avoid if/else statements.
Thanks!
square:if(thisComp.layer("VARIABLES").effect("xdiff")("Slider")>0) {
if(thisComp.layer("VARIABLES").effect("ydiff")("Slider")>0) {
180-(90-thisComp.layer("VARIABLES").effect("angle")("Slider"))
}
else {
180-(thisComp.layer("VARIABLES").effect("angle")("Slider")+90)
}}
else {
if(thisComp.layer("VARIABLES").effect("ydiff")("Slider")>0) {
-(180-(90-thisComp.layer("VARIABLES").effect("angle")("Slider")))
}
else {
-(180-(90+thisComp.layer("VARIABLES").effect("angle")("Slider")))
}}----------
circle:
if(thisComp.layer("VARIABLES").effect("xdiff")("Slider")>0) {
if(thisComp.layer("VARIABLES").effect("ydiff")("Slider")>0) {
180-(90-thisComp.layer("VARIABLES").effect("angle")("Slider"));
}
else {
90-thisComp.layer("VARIABLES").effect("angle")("Slider");
}}
else {
if(thisComp.layer("VARIABLES").effect("ydiff")("Slider")>0) {
-(180-(90-thisComp.layer("VARIABLES").effect("angle")("Slider")))
}
else
{
-(90-thisComp.layer("VARIABLES").effect("angle")("Slider"))
}}