ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

expression toWorld not changing

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Andy Engelkemierexpression toWorld not changing
by on Nov 28, 2016 at 4:55:41 pm

I'm trying to create an expression that keeps a light always pointed to a location, and has only it's X position changing to point to a null object which is parented to another layer. That's a mouthful.

But down to the issue I'm having, and maybe I'm just confused at how this works.
I thought, that toWorld would return an object's position in world coordinates regardless of the object's parent. So at any point in time, if you look at toWorld number, you'd see exactly where that anchor point is in the world coordinates.

First, my object isn't going where I expect it to.
Second, it doesn't move, although the null object Does move.

The light's point of interest has this:
GetX = toWorld(thisComp.layer("SuckSpot").transform.position);
x = GetX[0];
y = GetX[1];
z = transform.position[2];

The light position has this:
GetX = toWorld(thisComp.layer("SuckSpot").transform.position);
x = GetX[0];
y = transform.position[1];
z = transform.position[2];

The position, I only need to look at the null object's X position. But one thing seems odd. I didn't Add the layer position or anything, so why is it letting me move the object in all 3 axis?

I'm sure it's something simple, but I'm stuck.

Return to posts index

Darby EdelenRe: expression toWorld not changing
by on Nov 30, 2016 at 9:31:39 am

That's not the proper form for toWorld(). Here it is fixed:

l = thisComp.layer("SuckSpot");
GetX = l.toWorld(l.anchorPoint);

This stores the layer object in a variable called "l". The toWorld() is a method of the layer object so l.toWorld() calls the toWorld() function of the layer l.

For toWorld() to work correctly you need to provide a coordinate in the layer's coordinate system. The anchorPoint is usually a good option, l.anchorPoint returns the l layer's anchorPoint

So essentially the call "l.toWorld(l.anchorPoint)" is saying "Give me the position in world space of the anchor point of the layer l".

If your layer doesn't have an anchorPoint then you can provide an arbitrary coordinate, so for a light or camera:


Darby Edelen

Return to posts index

Andy EngelkemierRe: expression toWorld not changing
by on Nov 30, 2016 at 12:34:22 pm

Thank you, that works fine.

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 All Rights Reserved