Activity › Forums › Adobe After Effects › can you create an expression to “push” layers using another?
-
can you create an expression to “push” layers using another?
Posted by Erin Shelby on November 21, 2005 at 4:59 amHi all,
I’m wondering if it is possible to write an expression in which one solid can seemingly “push” another solid around. Ideally the setup is a rectangle that pushes around a square. In it’s simplist incarnation, I guess it would be only in one dimention (let’s say X) and when the Pusher hits the Square, the square will move along with it (as it if was parented) but when the Pusher moves backwards (-x) the Square will not follow it. Ideally, I’d like to be able to expand it for other directions, but just this one version seems like quite the feat alone.
-echo
Chris Zwar replied 20 years, 5 months ago 5 Members · 6 Replies -
6 Replies
-
Mylenium
November 21, 2005 at 5:58 amI don’t see why this shouldn’t be doable. Since you have acces to a layers velocity, one wouldn’t even need to bother with calculating the vectors. A simple conditional construct should do like
if(thisComp.layer(“Pusher”).velocity[0] < 0) {my_move =...) else{my_move=...}; I'm sure you can come up with something. Mylenium [Pour Myl
-
Dan Ebberts
November 21, 2005 at 6:38 amThis is one of those situations that’s difficult to do with expressions. The reason is that for the position expression of the “pushee” to be able to figure out where it should be, it needs to know the entire history of the movement of the “pusher”. The only way I know of that will work is to have the expression loop through every frame of the timeline to figure out where the pusher has been. It can be done, but it gets a little impractical if your comp is long. Anyway, here’s an example that works on the x axis. It assumes the pushee starts to the right of the pusher.
// assumes this layer is to the right of the pushing layer P = thisComp.layer("pusher"); // find pusher's max movement to the right so far maxX = 0; for(t = 0; t <= time; t += thisComp.frameDuration){ x = P.position.valueAtTime(t)[0]; if (x > maxX) maxX = x; } if (maxX + P.width/2 + width/2 > value[0]){ [maxX + P.width/2 + width/2,value[1]] }else{ value }Dan
-
Mike Smith
November 21, 2005 at 2:02 pmHi Dan
Wouldn’t it be possible to set up a “collision test” – just a check that the boundary of one square / rectangle does not overlap the other – then, if there is an overlap, move the “pushee” just enough pixels along to clear it …
Mike
-
Mike Smith
November 21, 2005 at 2:53 pmOr is this where we get stuck on can’t store a variable – in this case, target position …? Hmmm
-
Dan Ebberts
November 21, 2005 at 5:06 pmYeah, that’s the problem. Once the pusher moves away so there’s no longer any overlap, the pushee has no way of knowing that it had previously been pushed – except by using the Wayback Machine, as in my example. 🙂
Dan
-
Chris Zwar
November 21, 2005 at 7:42 pmWithout offering a solution (sorry!), I can suggest that if this is something you’re really into, then try looking at some simple physics equations. There are many which are freely available on the internet, just google for physics and you’ll find lots of free tutorials for undergrads.
After looking at Dan’s site, I went shopping for the book he recommened on Physics for Programmers, only to find that there were several and I didn’t write down the specific author of the one on Dan’s site. After reading through all of them (Borders is good for that) I chose “Mathematics and Physics for Programmers” by Danny Kodicek of Charles River Media Books. It’s got a lot of interesting things in there, many of which will be tedious but rewarding to adapt to After Effects expressions because of the lack of variables between frames, but as Dan says- you just have to loop the equations through everything that has already been done every frame. It isn’t that much harder for the programmer, it’s just slower to process.
Anyway if you’re into that sort of thing, I highly recommend that book.
-Chris Zwar
Motion Graphics Designer
Will animate for food
Reply to this Discussion! Login or Sign Up