Skip to content

Instantly share code, notes, and snippets.

@Wunkolo
Last active July 14, 2022 02:07
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wunkolo/984d73fc0a45b3d5aceb194f15a86923 to your computer and use it in GitHub Desktop.
Save Wunkolo/984d73fc0a45b3d5aceb194f15a86923 to your computer and use it in GitHub Desktop.
Spiderman home-coming mystery code solved
targetPos = thisComp.layer("target").toComp([0,0]); // Compensating for the missing "targetPos" variable
box = thisComp.layer("box");
boxTopLeft = box.toComp([0,0]);
boxBottomRight = box.toComp([box.width,box.height]);
// this is erroneous on their part. "deltaX" and "xDistanceToEdge" does not exist yet, commented out.
boxAnchor = box.toComp(box.anchorPoint);// xRatio = deltaX/xDistanceToEdge;
deltaVec = sub(targetPos, boxAnchor)
deltaX = deltaVec[0];
deltaY = deltaVec[1];
xRatio = 1;
yRatio = 1;
if(deltaX>0){ // target is right of anchorPoint
xDistanceToEdge = boxBottomRight[0] - boxAnchor[0];
xRatio = deltaX / xDistanceToEdge;
}else if(deltaX<0)
{
xDistanceToEdge = boxTopLeft[0] - boxAnchor[0];
xRatio = deltaX / xDistanceToEdge;
}
if(deltaY>0){ // target is below anchorPoint
yDistanceToEdge = boxBottomRight[1] - boxAnchor[1];
yRatio = deltaY / yDistanceToEdge;
}else if(deltaY<0)
{
yDistanceToEdge = boxTopLeft[1] - boxAnchor[1];
yRatio = deltaY / yDistanceToEdge;
}
ratio = (xRatio>yRatio)? xRatio:yRatio;
offset = div(deltaVec,ratio);
boxAnchor + offset;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment