Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects expression toWorld not changing

  • expression toWorld not changing

    Posted by Andy Engelkemier on November 28, 2016 at 4:55 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];
    [x,y,z];

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

    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.

    Simeon In ‘t veld replied 8 years, 6 months ago 3 Members · 3 Replies
  • 3 Replies
  • Darby Edelen

    November 30, 2016 at 9:31 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:

    l.toWorld([0,0,0]);

    Darby Edelen

  • Andy Engelkemier

    November 30, 2016 at 12:34 pm

    Thank you, that works fine.

  • Simeon In ‘t veld

    November 14, 2017 at 2:41 pm

    I tried this but I get 1.toWorld is not a function error. what do I do?

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy