Activity › Forums › Adobe After Effects Expressions › A Self-Referential Script
-
A Self-Referential Script
Posted by Ben Jaffe on May 3, 2008 at 8:51 pmThis code is in the object’s position expression box. As far as I can tell, this code should make the object accelerate. It is instead making the object move at a steady rate. Also, it’s not starting from 50,50 like it should, but instead, at frame 1, it’s jumping to 360,240. Can anyone tell me what I am doing wrong?
if(time==0) {[50,50]} //this is to give the object a starting position
else{offsetx = time;
offsety = time;transform.position + [offsetx, offsety]
}
//Thanks in advance!
Dan Ebberts replied 18 years ago 3 Members · 8 Replies -
8 Replies
-
Dan Ebberts
May 3, 2008 at 10:39 pmI think you’re assuming that the expression will use its results from the previous frame, which is not the case.
Something like this might give you what you’re after:
startPos = [50,50];
offset = time*time;
startPos + [offset,offset]Dan
-
Ben Jaffe
May 4, 2008 at 6:46 amHi Dan,
Thank you for your response. That would work, but my example in the post is a simplified version of what I’m doing. I am actually figuring out formulae for a bike wheel trailing a null object which drags around the front wheel of the bike. The idea is that I just drag around this null object, and the bike takes care of it’s own orientation, among other things. I figured trying to explain and post the whole thing would be overwhelming for the forums, so I made a simple example that would get across the basic concept I need help with.Can you think of a way to use the values from the previous frame in the expression? There’s gotta be a way. If there isn’t, it seriously limits what I can use expressions for, and it means a lot more toiling over keyframes that should be able to figure themselves out.
Ben
-
Dan Ebberts
May 4, 2008 at 7:28 amUsually there’s a way around the limitation. Worst case, you can set up a loop that goes through the timeline, frame by frame, and calculates the value of the expression up to the current frame. Could bog down though, if your comp is very long and/or the expression is very complicated.
Dan
-
Darby Edelen
May 4, 2008 at 7:29 amThe way I’ve done this in the past is by just finding the difference between the Null’s current position and it’s position at the start frame, then rotate the tire that many pixels… To do that you need to know the diameter of the tire and use:
circumference = π * diameterDarby Edelen
Lead Designer
Left Coast Digital
Santa Cruz, CA -
Ben Jaffe
May 4, 2008 at 5:24 pmDarby and Dan, thanks for the responses.
I may do what you suggested Dan, but it will be a long comp, and will definitely be very bogged down.
But ultimately, there is no way for the object to use its position from the previous frame that either of you know of? No workarounds with other nulls or sliders… Is it the fact that it’s a loop which is causing the problems?
-
Dan Ebberts
May 4, 2008 at 6:53 pmNo, it’s the fact that an expression can’t access a previous value of that expression. Whenever an expression refers to the property to which it is applied, it gets the pre-expression (keyframed) value of that property.
Dan
-
Ben Jaffe
May 4, 2008 at 6:58 pmOh okay, that makes a lot of sense. Is there a way to get its final position post-expression? I know there’s code to get the real rotation of an object that has auto-orient turned on. Anything like that for position that you have seen?
And thank you so much for your help!
-
Dan Ebberts
May 4, 2008 at 8:03 pmYou can get the past, present, and future post-expression postion values from an expression applied to any other layer or property, just not from within the position expression generating the value.
You can try all sorts of schemes – use a position expression applied to a null to pick up the post-expression value of the layer you’re interested in and then read that value from the target layer’s expression. It doesn’t work. It might seem to work for one frame, but it doesn’t work.
You need a better plan. 🙂
Dan
Reply to this Discussion! Login or Sign Up