Skip to main content
brandonb96942845
Inspiring
March 1, 2023
Question

How To: Change Property if Two Objects Overlap?

  • March 1, 2023
  • 3 replies
  • 1498 views

Hi all,

 

So we were able to solve one problem in an unexpectedly easy way the other day, and I wanted to see if maybe we could solve another.

Short version: I'm using AfterEffects to replicate the Windows 10 interface for a software demo, and I have everything set up to emulate the various effects (i.e. mouse-hover, left-click, and so on). Right now, if I want to simulate a mouse-hover of one of the desktop icons, I have to move the mouse cursor (a PNG with its anchor point set to [0,0]) over it, and then manually watch to see when the mouse-hover highlight would appear, and adjust the layer's opacity by hand. I then have to do likewise when the cursor moves away, and this can get very tedious if I have to adjust the movement of the mouse cursor.

My question is: if I have a layer specifically for mouse-hover effects, is it possible to cue it (maybe with an IF/ELSE statement or something similar) to ONLY become visible when the mouse icon PNG overlaps with it? (In other words, 0 opacity to make it invisible, then when the mouse cursor PNG overlaps with it, instantly change the opacity to 100, then back again when the cursor PNG is no longer overlapping)

This topic has been closed for replies.

3 replies

Mylenium
Legend
March 29, 2023

You have not offered any info about the specifics of your setup, so it's impossible to know why it's not working. Collapsed transformations could mess up transforms, effects affect the pixel values and so on. You have to provide that info and/ or a screenshot of the situation.

 

Mylenium

brandonb96942845
Inspiring
March 29, 2023
ShiveringCactus
Community Expert
Community Expert
March 31, 2023

I know there's two threads going on, but as soon as you started describing needing interaction with more than one target my immediate thought was: 

 

  • Create a layer with all the targets on
  • Point the mouse pointer's sampleImage to that
  • Hide the target layer at the bottom of the comp (or I think you can turn it off).

 

This way all issues with nested comps, collapse transformations, extra complex expressions etc... go away and you have your target shapes at the same comp level as your mouse.  At which point, changing shapes becomes a matter of keyframing position/opacity - but that's fine too, because your mouse keyframes will be right there

Mylenium
Legend
March 29, 2023

The expression compares pixel values and thus the layer type doesn't really matter. Unless there are specifics involved with collapsed transformations, certain effects etc. there are no extra steps required.

 

Mylenium

brandonb96942845
Inspiring
March 29, 2023

And yet, it's happening. Maybe instead of telling me "there are no extra steps required," perhaps you could try actually helping me figure out why this is happening? Seriously, if you can't offer practical solutions do us both a favor and keep your comments to yourself.

Dan Ebberts
Community Expert
Community Expert
March 1, 2023

Something like this would probably be simplest:

 

L = thisComp.layer("mouse");
p = fromComp(L.toComp(L.anchorPoint));
sampleImage(p,[.5,.5],true)[3] > 0 ? 100 : 0

 

brandonb96942845
Inspiring
March 1, 2023

I will give that a try, Dan, many thanks as usual!