Page 1 of 1

newbie: add value to position

Posted: November 27th, 2005, 9:58 am
by frankfunk
hopefully this is not a stupid question, but due to aes incapability to handle global variables and to read the value of the property it's in, i couldn't figure this one out:

i have a 0-object with a property animated with keyframes with values from 0 to 10. every frame, i want to move another object as many pixels to the right as the value of the property is.

my problem is, that i can't add to the position so that it becomes a steady move to the right. the object just moves to the property instead, twiggling around.

i know there has to be a workaround, but how?

thanks!

Posted: November 28th, 2005, 11:43 am
by goldomega
If you are animating the position of your 0-layer, you might be having a problem adding arrays. The problem is that some properties, like position, call for an array of all three axes [x,y,z] rather than for just one axis. So when you add the position of your null to the position of your layer, your expression is really adding everything: [x,y,z]+[x,y,z]. The solution to this is to access only the axes you need in order to animate the layer the way you want.

So rather than using this on your child layer's position:

thisLayer.position+thisComp.layer("null 1").position


try:

x=thisLayer.position[0]+thisComp.layer("null 1").position[0];
y=thisLayer.position[1];
z=thisLayer.position[2];

[x,y,z]



This is meant as a very basic example of how to call values from arrays. For a more detailed explanation, visit Dan Ebbert's expression site at http://www.motionscript.com and look for the section on arrays. There are also tutorials under the tutorial section here that briefly outline how to use arrays.

Good luck!

Posted: November 28th, 2005, 12:44 pm
by frankfunk
thanks a lot, goldomega, but i think you misunderstood me. most likely this happend because of my bad english - please excuse that, i'll try again.


to keep this easy, let's assume that the value of this property is always 5:

thisComp.layer("adjust").myproperty

now i have a solid with position [0,0], which every frame i want to move as many pixels to the right as the value of the property discribed above. but if i state in the position property:

[position[0]+thisComp.layer("adjust").myproperty, position[1]]

the position changes to [5, 0] and stays like that. this happens because "position[0]" is the position the object would have without any expressions applied to it.

what i want it to do is to move 5 pixels to the right in every frame, moving from 5 to 10 to 15 to 20 to 25...

how can i achieve that?

Posted: November 29th, 2005, 6:34 am
by Mylenium
frankfunk wrote:thanks a lot, goldomega, but i think you misunderstood me. most likely this happend because of my bad english - please excuse that, i'll try again.


to keep this easy, let's assume that the value of this property is always 5:

thisComp.layer("adjust").myproperty

now i have a solid with position [0,0], which every frame i want to move as many pixels to the right as the value of the property discribed above. but if i state in the position property:

[position[0]+thisComp.layer("adjust").myproperty, position[1]]

the position changes to [5, 0] and stays like that. this happens because "position[0]" is the position the object would have without any expressions applied to it.

what i want it to do is to move 5 pixels to the right in every frame, moving from 5 to 10 to 15 to 20 to 25...

how can i achieve that?
You need to have something that changes and drives the animation, it's as simple as that. You only created a static expression. Incorporate "time" as a multiplier/ factor and everything will work. It could look like:

my_offset=5;
my_frame=timeToFrames(time);
X=position[0]+my_offset*my_frame;
Y=position[1];

[X,Y]

BTW, you should not confuse properties and methods with values. Your example, "thisComp.layer("adjust").myproperty" must not necessarily work in every case. There are many properties such as scale and position that use arrays and you will quite often find yourself in situations where you need to tell your expressions whicxh values to use.

Mylenium