Playing around with code-driven animation, this effect was created entirely with code in After Effects. I created a script which calculates the speed of movement of the tree and makes it bend accordingly, even with some springy physics when it stops 🙂