What's the best way to calculate a layer's velocity along one axis (X in this case) during an animation?
the general equation for velocity is displacement / time passed
so you to need to pick a time epoch... 0
and in your case it will be (x1 - x0)/time elapsed
where x1 is where you ended up and x0 is where you began
time elapsed coukd be acieved with two date time stamps from system
t0 == 0 and t1 == time elapsed
Got it, thanks. Must be something like that then, right?
savelayerXposition = layer.x
Utils.interval 0.5, -> #every 0.5 seconds.....velocityX = (layer.x - savelayerXposition)/0.5 #calculation.....savelayerXposition = 0 #clears savelayerXposition
Here is what works for me:
velocityX = 0saveX = 0refreshrate = 0.06
Utils.interval refreshrate, ->....saveX = layer.x
.....Utils.delay refreshrate/2, ->..........velocityX = (saveX - layer.x)/refreshrate..........print velocityX
Thanks again, Doug!