# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression for Making a Layer Travel in a Triangle

• # Expression for Making a Layer Travel in a Triangle

Posted by on July 22, 2009 at 7:42 pm

Hey Everone,

So, I don’t mean to saturate this forum, but what can I say, I need some more help!

My post this time is related to my previous post found here: https://forums.creativecow.net/readpost/227/13654

Now, however, I need to find an expression that will allow me to animate with a triangle motion path. Again, I would love to animate using a mask as a motion path, but that method has a tendency to be less graceful than some simple scripting. I basically need to animate an object traveling in a triangle shape with the equilateral triangle pointing upwards.

Thoughts?

PS – The triangle shape driving the motion needs to have rounded corners – eek!

What makes you explode?
http://www.explosivegraffix.com

2 Members · 3 Replies
• 3 Replies
• ### Ben Rollason

July 23, 2009 at 10:34 am

The following draws a triangle between the three points defined by three layers. They could equally well be points that you have inputed manually.

The rounded corner thing is tricky. Either the math gets really complicated. You’d need to have a point moving distant from your original point, but perpendicular to it. At each vertex, you would pause the initial movement for a time and instead animate the point in the arc of a circle around the vertex.

How long that time is depends on the relative length of the sides of the triangle to the arcs of the circles.

Like I said, complicated.

Couldn’t you just get the damn thing to follow a spline path? 🙂

-Ben.

http://www.benrollason.com

• ### Ben Rollason

July 23, 2009 at 10:35 am

Hmmm. I posted the expression in the box, but it didn’t come up, so here it is again…

-Ben.

``` p1 = thisComp.layer(1).position; p2 = thisComp.layer(2).position; p3 = thisComp.layer(3).position;```

``` tpoints = [p1, p2,p3]; tduration = 300; //frames tFrame = time/thisComp.frameDuration; tSector = Math.ceil((tFrame) / (tduration/3)); tSector = (tSector < 1?1:(tSector>3?3:tSector)); tBetween = [tSector % 3,tSector -1]; tStage = tFrame % 100; tP = (tpoints[tBetween[0]]*tStage+ tpoints[tBetween[1]]*(100-tStage))/100; if (tFrame > tduration) { tP = p1 }; ```

http://www.benrollason.com

• ### Mark Walczak

July 23, 2009 at 2:37 pm

Wow, Ben, that’s really incredible stuff. This is a great help!

I could animate the object with a motion path, but I was looking for a more simple solution (as I need to do all sorts of funky stuff with ramping the rate of travel around the triangle, etc). Also, using an expression forces me to learn the code and sort of reverse-engineer certain scripting concepts, as I am still a novice. Your help is very, very much appreciated.

Also, I checked out your reel and was floored – you have some killer work!

Thanks again, this is very helpful,

Mark

What makes you explode?
http://www.explosivegraffix.com

We use anonymous cookies to give you the best experience we can.