Hi! I am working on a video that micmics something like selecting an object with a mouse cursor. It should go like when you hover the arrow on top of the object it should scale up a bit. I did that using this expression:
point = thisComp.layer("Motion Controller").transform.position; //controlls the cursor
housePoint = thisLayer.sampleImage(point, [.5,.5]); //produces a value of "1" when the null is over this layer or "0" when not.
You want to use either the distance of the cursor from the (center of the) object OR the time of how long the cursor has been over the object (or how long since it left the object) to control the scaling.
Distance to the center of the object would be easier. Calculate the distance and then remap that distance to the scale with the linear() expression. Linear() is a very handy expression to know. For a bit more advanced version, replace with the ease() expression. Probably not necessary here.
If you rather have the scaling happen when approaching the edge of the object, you can, to a degree, simulate that by using sourceRectAtTime() to find out the width and height of the object and include those in calculating the distance of the cursor from the containing rectangle of the object.
Time is more involved. You need a loop that counts backwards from current frame, one frame at a time, up to the length of the transition, and checks whether the cursor is over the object or not. As a result you either get the number of frames the cursor has been over the object or when it has left the object or that it has not been over the object at all. Then you can use the linear() or ease() expression to change the scale based on time. Definitely more complex a procedure.
In case that proves too difficult, I realized there's an easier way to do this, which I occasionally use. You can use your original expression for the scale, but apply it to a duplicate of your layer. Then convert the expression to keyframes and finally add a smooth() expression to the layer's scale (keeping the keyframes). It will give you a "baked" animation with a smoothing expression applied to the scaling over time. Keep the original layer with the editable expression in case you need to adjust, just hide it.
Wow. I didn't think it would be that complex. I need to study first the functions needed for the process that you gave. I think it would be faster now if I would just animate them manually. But I definitely need this for my upcoming project cause that has a lot of objects to hover around. Thank you so much Kalleheikki.
on Apr 27, 2019 at 10:42:41 am Last Edited By Kalleheikki Kannisto on Apr 27, 2019 at 10:46:44 am
You can always try the easy way (distance of the cursor from the anchor point of the layer) first and if it works, you don't need to bother with the more complicated one that takes the layer dimensions into account.