Adobe After Effects Expressions Forum
If Position Increases or Decreases
If Position Increases or Decreases
by Martin Eke on Aug 13, 2019 at 12:20:56 pm

Hi everybody, I'm pretty new here but I've been lurking for a while trying to figure this out.

I've got a simple position movement. Got 3 keyframes across 2 seconds. My shape layer moves from one side of the screen to the other, before moving back to its original position. Got some simple easy ease on this as well.

On the same shape layer, I've got an expression on the Rotation property.

position.speed/80

This is allowing me to rotate my shape layer based on the speed of the position property. This works perfectly for the first half of the animation, when it moves from the left hand side of the screen to the right... However, I want to be able to reverse this expression so that when the x position property is decreasing, the rotation happens in the opposite direction.

If anyone could help out, I'd really appreciate it!


Re: If Position Increases or Decreases
by Dan Ebberts on Aug 13, 2019 at 3:40:36 pm

Try this:

r = position.speed/80;
position.velocity[0] > 0 ? r : -r


Dan




Re: If Position Increases or Decreases
by Martin Eke on Aug 14, 2019 at 8:29:01 am

Oh wow, yep... That 100% works!

Would you mind me asking what the '?' is doing with the expression?

Thank you so much! This is exactly what I was looking for.


Re: If Position Increases or Decreases
by Dan Ebberts on Aug 14, 2019 at 10:03:36 pm

It's a condensed form of if/else. Just Google JavaScript ternary operator.

Dan







© CreativeCOW.net