-
Expression to mimic hover state for rectangular shaped layers
Hi there,
I’m looking for the best way to mimic a hover state in after effects.
I make a lot of tutorial videos where I animate a cursor placed over a “button layer” and
then an “active button layer” over it is trimmed to only appear while I have the cursor over it.I have been using this expression to affect the opacity of the “active button layer” when the cursor’s anchor point gets within a certain distance of the anchor point.
min_distance=49.9;
max_distance=50;
c=comp(“MAIN COMP”).layer(“cursor_black.eps”);
d=length(to_world(anchor_point), c.to_world(anchor_point));
linear(d, min_distance, max_distance, 100, 0)This works great for buttons that are square or circular (where the anchor point is pretty much the same distance from all the edges), however, buttons that are rectangular where the distance from the anchor point to the edge of the layer is very different depending on whether you measure from the anchor point to the top edge or bottom edge vs from the anchor point to the left edge or right edge.
Although this is working pretty well, I’m not sure if distance to anchor point is the best way to go about achieving my goal or if there is maybe some way to use the alpha information of the layer so it can be exact and I don’t have to change the min and max distance in the expression for each button’s dimensions, if thats even possible.
I tried using Dan Ebberts’ Collision Detection expression,
which seemed like a great answer, but I could not get it to work. : /Thank you in advance!