Skip to main content
Participant
February 7, 2024
Question

How to change the color of the object based on it's side movement.

  • February 7, 2024
  • 1 reply
  • 538 views

Imagine this:
A murmuration of Starlings. When a bird moves to the left, it becomes green, and once they start moving to the right, it becomes red. In that way, we'll have green and red birds simultaneously, depending on which side they are moving to.

Does anyone know how to do it in AE, especially the color transition?
The Murmuration, I already found a way.
https://www.creationeffects.com/effects/murmuration-effect

This topic has been closed for replies.

1 reply

Dan Ebberts
Community Expert
Community Expert
February 7, 2024

I think the simplest approach would be to start with a color expression like this:

v = transform.position.velocity;
v[0] > 0 ? [1,0,0,1] : [0,1,0,1]
Participant
February 7, 2024

Thank you Dan.
I tested it with a single element, and it seems to work.
Could you explain the logic of this expression? I'm not very familiar with expression yet.
Would it be possible for me to use orange and purple instead of green and red?

Again, thank you very much

 

Dan Ebberts
Community Expert
Community Expert
February 7, 2024

The expression just looks at the x component of the layer's velocity (v[0]). If it's positive, the layer is going to the right, otherwise to the left. You could define the colors with variables, like this:

leftColor = [1,.5,0,1]; // orange
rightColor = [.3765,0,1,1]; // purple
v = transform.position.velocity;
v[0] > 0 ? rightColor : leftColor