# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expression to define two positions, tween back and forth

• # Expression to define two positions, tween back and forth

2 Members · 3 Posts
• ### Benjamin Allison

January 30, 2014 at 10:13 pm

So I want to do something simple: define two sets of coordinates (a “from” and a “to” position), along with a duration in frames. I want the animation to be executed, then reversed, and looped.

I know I can set two keyframes, and use `loopOut(“pingPong”);` but I want to try and achieve this with a simple expression.

I’m sure it’s possible!

• ### Darby Edelen

January 30, 2014 at 10:39 pm

[Benjamin Allison] “I know I can set two keyframes, and use `loopOut(“pingPong”);` but I want to try and achieve this with a simple expression.”

loopOut(“pingpong”) is a simple expression! 🙂

You won’t be able to define any spatial paths any other way, but this should work:

```d = 5; fd = d * 2; p1 = [200, 500]; p2 = [500, 200]; t = (time - inPoint) % fd;```

``` ```

```if(t <= d) linear(t, 0, d, p1, p2); else linear(t, d, fd, p2, p1); ```

This starts from p1 at the beginning of the layer and runs to p2 over 5 seconds, then goes back to p1 and begins again. If you want the animation to ease in to each point you could use the ease() function instead of linear() providing the same arguments.

-Darby

Darby Edelen

• ### Benjamin Allison

January 30, 2014 at 10:46 pm

You’re a king among men!

The concept is so simple I can’t believe an hour of googling got me zilch.

Thanks so much Darby!

Viewing 1 - 3 of 3 posts