PDA

View Full Version : Attn Expression Experts: Noob question.



fgreen
06-07-2012, 02:41 PM
Hi everyone,

I'm trying to understand the syntax for expressions, but am having trouble with something I think should be easy.

I have an object serving as a floor in a scene (floor)

I have a null (null)

I have the null parented to the camera, so it follows the camera around.

I'd like to have an expression limit the y position of the Null to that of the floor object, so it follows the camera in X and Z, but essentially stays at floor level for the Y position.

From the documentation this is the expression I came up with and placed it in the Null.Position.Y channel in the graph editor:

[floor.Position.Y,Time]

From the documentation it seems like this should override the Y position calculated by layout and keep the null directly under the camera, or floor level at the current frame. This makes sense to me, as this is how it would work in AE.

The only problem is.... it doesn't work. After applying the expression, the Null's Y position is still that of the camera.

I guess I must be totally missing something. Is the "parenting" overriding the expression? Instead of parenting do I need expressions for the X and Z as well?

Any help greatly appreciated. Thanks.

3DGFXStudios
06-07-2012, 02:50 PM
I think you do need to have the null parented to the camera. Or use world position

fgreen
06-07-2012, 02:56 PM
3DGFXStudios, thanks for the reply. I have the Null parented to the camera already. I'm not following the world position suggestion. Can you elaborate?

3DGFXStudios
06-07-2012, 03:42 PM
Don't parent the null to the cam. Let it follow the x and z with an expression and apply this to the Null's Y channel [Camera.Position.Y]>=[floor.Position.Y]?[Camera.Position.Y]:[floor.Position.Y]

If the Cameras y position is bigger than or equal to the floors Y pos the null follows the camera.

jeric_synergy
06-07-2012, 05:07 PM
I was just messing around w/expressions, and I kept forgetting to use the APPLY button: I'd write out the correct expression but never hit APPLY.

That doesn't work.
+++

I tried to recreate your LWS, and it didn't work for me either. I tried THIS:


wpos[FakeFloor.Position.Y]

and also THIS:


[FakeFloor.Position.Y]

Neither worked.

Perhaps the parenting is evaluated LAST.
+++++
Attached is a scene that works substantially like you wanted. It appears that PARENTING screws up the Expressions (!!!).

Somewhere there must be a list of the order in which motions are expressed. It might be something like:

modifiers
expressions
parenting
keyframes


(or not at all that way, but like that....)

3DGFXStudios
06-08-2012, 01:22 AM
I was just messing around w/expressions, and I kept forgetting to use the APPLY button: I'd write out the correct expression but never hit APPLY.

That doesn't work.
+++

I tried to recreate your LWS, and it didn't work for me either. I tried THIS:


wpos[FakeFloor.Position.Y]

and also THIS:


[FakeFloor.Position.Y]

Neither worked.

Perhaps the parenting is evaluated LAST.
+++++
Attached is a scene that works substantially like you wanted. It appears that PARENTING screws up the Expressions (!!!).

Somewhere there must be a list of the order in which motions are expressed. It might be something like:

modifiers
expressions
parenting
keyframes


(or not at all that way, but like that....)

Local space vs world space is a big difference for parented stuff.
Maybe it didn't work because you didn't need brackets.
This works fine Floor.wpos(Time).y just to follow a channel of a different object in world space. Don't know where you where after...

jeric_synergy
06-08-2012, 01:34 AM
Local space vs world space is a big difference for parented stuff.
Maybe it didn't work because you didn't need brackets.
This works fine Floor.wpos(Time).y just to follow a channel of a different object in world space. Don't know where you where after...
Did that work with parenting?

(I'm not the OP, so I'm not sure what he was after.)

3DGFXStudios
06-08-2012, 02:23 AM
If you parent it you'll get double transformations and it won't stop a floor level because it's following the camera as well so you have to compensate for that.

Like this.

[Camera.Position.Y]>=Floor.wpos(Time).y?Camera.wpos(Time).y-Camera.wpos(Time).y:Floor.wpos(Time).y-Camera.wpos(Time).y

;)

But it's a bit pointless to parent it.

3DGFXStudios
06-08-2012, 02:45 AM
Here's the scene...

RebelHill
06-08-2012, 03:47 AM
Yeah... as 3dgfx says... its easier to use the expression to make the null follow the camera XZ, whilst having the null NOT be a child of the camera at all, then put it anywhere u want in Y.

In fact, using expressions, this is the only way to do what you want, as whilst you can GET somethings world position in an expression, you cant APPLY to an items world position (only its parent space).

You could however do it with constraints (either way round), which is quicker to setup than the expression anyhow.

Either have the null unparented from the cam, set the cam as its position item, and set the X and Z channels to same as item. OR u can also have the null parented to the camera, set the floor as its position item, and set the Y to SAI, with world checked.

jeric_synergy
06-08-2012, 08:02 AM
OR u can also have the null parented to the camera, set the floor as its position item, and set the Y to SAI, with world checked.
"SAI"??

+++
I've been trying to think of a situation where one would absolutely need the parenting, but I can't. Perhaps if someone were also using MetaLink (which requires parenting), but that's pretty obscure.

fgreen
06-08-2012, 08:10 AM
Thanks for all the replies. Based on 3DGFXStudio's comment about two expressions in the X and Z, I put the attached scene together. I was basically looking for a way to automatically report the camera's distance from the ground, also using range finder. It occured to me that as long as the floor object doesn't move, I could ignore it. So I placed the null at zero y and expressions on the X and Z. Moving the Camera causes the null to follow, but stay at zero Y.

I saw that jeric_synergy"s posted an example that is almost identical after I went home yesterday, but his doesn't have the "time" arg. So I'm guessing it is optional and assumed if left off?

Two questions for 3DGFXstudio:
First, in your example it looks like the value for Position.Y in the square bracket is being "filled" by the code on the right of the "=" sign? Is that correct? (I'm going to have to study this for a while to understand how it works-- I'll have to start by looking up the ? operator again...:)

Also, before trying an expression I tried to use constraints. I just parented the Null to the camera and tried to put a constraint on the Y in the motion options. I guess I don't understand the motion panel, as well as I thought, because I couldn't get that to work either.

Could any of you explain how to do the same thing with parenting and constraints? Or maybe do another quick sample scene?

Might as well learn the other method as well... once again thanks for all the input.

jeric_synergy
06-08-2012, 08:44 AM
It appears to me that the offset of parenting is applied after the expressions are evaluated: if so, parenting will always override expressions.

Something's got to come last.

As a practical matter, how is parenting a necessity in this case?

++
If Time isn't specified, it's assumed to be the current frame.

fgreen
06-08-2012, 08:47 AM
It isn't really necessary. It's just that I tried to use parenting and constraints first, but could not get it to work.

Since 3DGFXStudios suggested it as an option, I'd like to know how to do it.

RebelHill
06-08-2012, 09:24 AM
I kinda already explained it in my post, but if you're not familiar that well with the whole constraint system, you'd do well to get the RHR 3 hours thing from my sig and watch vid1.

3DGFXStudios
06-08-2012, 09:55 AM
I'll explain whats happening in the expression.

the expression:
[Camera.Position.Y]>=Floor.wpos(Time).y?Camera.wpos(Time).y-Camera.wpos(Time).y:Floor.wpos(Time).y-Camera.wpos(Time).y

the expression with explanation: A <= B ? C (True): D (False)

[Camera.Position.Y]>=Floor.wpos(Time).y If the Cameras Y position is bigger than the Floors world position it does --> ? Camera.wpos(Time).y-Camera.wpos(Time).y And if not it does this --> :Floor.wpos(Time).y-Camera.wpos(Time).y

To compensate for the double transformations I subtract some values, if you don't have the Null parented you don't have to subtract anything.

3DGFXStudios
06-08-2012, 09:57 AM
It appears to me that the offset of parenting is applied after the expressions are evaluated: if so, parenting will always override expressions.

Something's got to come last.

As a practical matter, how is parenting a necessity in this case?

++
If Time isn't specified, it's assumed to be the current frame.

It doesn't have anything to do with what go's first. Expressions work in parent space. RebelHill explained it very well.

jeric_synergy
06-08-2012, 10:32 AM
It doesn't have anything to do with what go's first. Expressions work in parent space. RebelHill explained it very well.
Parent space versus object space? The nomenclature is confusing me here.

fgreen
06-08-2012, 10:37 AM
Rebel Hill, I get it now... I went back and looked at my "constraints" scene again. Thought I had set it up like in your post, but I had clicked the Y Pos Limits box, as I thought it needed to be checked to "activate the controls in the Y section-- not sure why. Once I unchecked that box it was working as expected.

I think you are right-- this is easier than setting up the expressions, and does exactly the same thing.

fgreen
06-08-2012, 11:29 AM
3DGFXStudio, I think I am following the expression now. It looks like the ? and : is the syntax to set up an if/then conditional structure on a single line? I've been reading through the Expression docs but haven't come across that yet. Anyway, thanks again for the detailed explanation.

jeric_synergy
06-08-2012, 12:21 PM
I think you are right-- this is easier than setting up the expressions, and does exactly the same thing.
Just sayin': my setup works even if the floor is moving. :hey: