FORUMS: list search recent posts

Creating an expression to correspond with an moving object, and live change of X,Y,Z values

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Josey Zadoria
Creating an expression to correspond with an moving object, and live change of X,Y,Z values
on Nov 24, 2014 at 3:51:10 am
Last Edited By Josey Zadoria on Nov 24, 2014 at 3:53:20 am

I looking for an easy way, using an expression to have a Moving object, as it moves, to have X,Y,Z values change along with it in a display function. I already tried by linking the text, which I created three layers (x,y,z) I basically alt clicked the position of each layer, and then using a Math,floor script I picked whipped to the position of the object layer. The only problem is I don't know how to get higher values like say over 1000, which is desirable in trying to create a realistic satellite movement feature.

I included a link in which I am working on a similar project to show you what I am talking about. If you notice in the bottom left hand corner, the x,y,z values change as the target dials move. If anybody has any suggestions, I would greatly appreciate it.








Thanks


Return to posts index

David Conklin
Re: Creating an expression to correspond with an moving object, and live change of X,Y,Z values
on Nov 24, 2014 at 6:10:30 pm

The simplest answer, I think, is to simply choose a number by which to multiply your position values. For instance, if your layer rests at [960, 540, 100], simply multiplying those values by 10 would give you [9600, 5400, 1000].

I'm including an expression which would do this for you. I'm also writing in a 'clamp', so that values don't exceed 10,000 or go below -10,000. You could, of course, alter this to fit your purposes.

The 'scaler' value can also be made into values less than 1 (i.e. .4 or 1/8) to make smaller values. I've also taken the liberty of removing the decimals for you using Math.floor (as you had done), but if you'd like decimals feel free to remove that code.

This expression assumes that the thing you're tracking is called 'satellite' and is in the same comp as your text, you can change the expression to fit your needs if this does not work in your situation.

Hope this is helpful, happy expression-ing!

//this goes on source text of
//a text layer.

//get the thing we're dealing with
var cntrl = thisComp.layer("satellite")

//get positions of said thing
var xPos = cntrl.transform.position[0];
var yPos = cntrl.transform.position[1];
var zPos = cntrl.transform.position[2];

//make a scaler value to amplify values
var scaler = 10;

//value caps.
//set these to values you don't want
//to go above/below.
var maxVal = 100000;
var minVal = -100000;

//multiply, but make sure we don't
//go outside of our range.
var xPos_make = Math.floor(Math.min(Math.max(xPos * scaler, minVal), maxVal));
var yPos_make = Math.floor(Math.min(Math.max(yPos * scaler, minVal), maxVal));
var zPos_make = Math.floor(Math.min(Math.max(zPos * scaler, minVal), maxVal));

//make the string
"X: " + xPos_make + "metres" + "\r\n" +
"Y: " + yPos_make + "metres" + "\r\n" +
"Z: " + zPos_make + "metres" + "\r\n"


David Conklin
Motion Designer


Return to posts index

Josey Zadoria
Re: Creating an expression to correspond with an moving object, and live change of X,Y,Z values
on Nov 27, 2014 at 5:15:05 am

Hello Mr. Conklin,
Thank you for responding and taking the time to write this out. I still have a few questions regarding my project.




I was a little confused on the scale script)

Anyway as you can see from my image, 1. refers to the actual object that all of the text is linked to. As well as the script that I originally used. In order to get the z values to work, will this layer have to be 3D, and then animate it along the z axis in order for it to work? If that is the case, then it will be much easier to deal with. In fact that is what I had did primarily and it worked, I just want to get the values to reflect, as you suggested between 1000 and whatever it ends at, say 12000.

Using my script example, can you show me how it will look like with your suggestions, just so I can have a reference, and is easier to understand how the script should like? (I am a novice when it comes to expressions, so this is an area in which I must learn more about)


Thank you again for your time in explaining this, and it is greatly appreciated.


Best
Josey

Thnak


Return to posts index


Josey Zadoria
Re: Creating an expression to correspond with an moving object, and live change of X,Y,Z values
on Nov 28, 2014 at 9:39:06 am
Last Edited By Josey Zadoria on Nov 28, 2014 at 9:44:36 am

Hello Mr. Conklin,
Thank you for responding and taking the time to write this out. I still have a few questions regarding my project.




I was a little confused on the scale script)

Anyway as you can see from my image, 1. refers to the actual object that all of the text is linked to. As well as the script that I originally used. In order to get the z values to work, will this layer have to be 3D, and then animate it along the z axis in order for it to work? If that is the case, then it will be much easier to deal with. In fact that is what I had did primarily and it worked, I just want to get the values to reflect, as you suggested between 1000 and whatever ity ends at.

Hello again Mr. Conklin:

I tried what you suggested, but I am not sure if I did it right because I am getting an error message at line 1.

This was what my expression looked like in the text layer titled


Also the SATNAT (which is the title of the moving object) layer in which I have the values above typed in is the start points, as I also have the "SATNAT layer set to three D.

Is it possible to tell me what I did wrong here? I really appreciate it. After several attempts at changing the start values, or careful I did not mess things around I am completely stumped.


Thanks
Josey


Return to posts index

Josey Zadoria
Re: Creating an expression to correspond with an moving object, and live change of X,Y,Z values
on Nov 28, 2014 at 9:46:01 am
Last Edited By Josey Zadoria on Nov 28, 2014 at 9:53:19 am

Mr Conklin,

Sorry, here is the Expression code that I tried in project on my Layer

var cntrl = thisComp.layer("SATNAT")
var xPos = cntrl.transform.position[1290.9];
var yPos = cntrl.transform.position[738.84];
var zPos = cntrl.transform.position[10];
var scaler = 10;var maxVal = 250000; var minVal = -120000 var xPos_make = Math.floor(Math.min(Math.max(xPos * scaler, minVal), maxVal)); var yPos_make = Math.floor(Math.min(Math.max(yPos * scaler, minVal), maxVal)); var zPos_make = Math.floor(Math.min(Math.max(zPos * scaler, minVal), maxVal));"X: " + xPos_make + "metres" + "\r\n" + "Y: " + yPos_make + "metres" + "\r\n" + "Z: " + zPos_make + "metres" + "\r\n"


Return to posts index

David Conklin
Re: Creating an expression to correspond with an moving object, and live change of X,Y,Z values
on Dec 1, 2014 at 3:11:37 pm

Hey Josey.

My apologies for not getting back to you sooner, I was away from the computer for the long weekend.

I think you're getting confused about how to use the expression. position[#] does not refer to an explicit position value, but instead one property of the position vector. I'm attaching a file to show you how to use this expression properly. Essentially, you have a layer that's 3D and this expression reads its X, Y and Z values, multiplies them by a scaler number, and then formats those values to use on a single text layer's source text property

8251_satellitetrack.aep.zip

Hopefully this is helpful to you.

Good luck!

David Conklin
Motion Designer


Return to posts index


Josey Zadoria
Re: Creating an expression to correspond with an moving object, and live change of X,Y,Z values
on Dec 12, 2014 at 9:11:50 am

Hello Mr. Conklin again!

Please disregard my last correspondence to you. I was able to figure it out using your script. It seemed the further I tried various things, it started making sense in what I was doing wrong.

Thank you again for your help, as this now is working exactly the way I need it too.

Warm wishes to you and you family during the holidays!

Best

Josey Zadoria


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]