I have some questions:
Are the cars using Follow Path, or parented to Armatures/objects with Curve Mods, to move along the roads?
This means they are moving in only one axis (although they are moving in more in the Real World).
Are the cars, just keyframed to specific locations, which could involve movement in multiple axes?
This will drastically alter the way we try to solve this problem - if the answer to 1 is YES and the answer to 2 is NO - that makes life mush easier.
I did some experimenting using just Animation Nodes and came up with this solution:
And the node tree in more detail:
So - the node tree looks at the object’s location in the current frame, one frame ago and 2 frames ago.
To get speed we need two locations.
To get acceleration we need two speeds.
Hence, I need to know where the object was 1 and 2 frames in the past as well as where it is now - can we agree on this?
To get a speed I find the difference between two locations and multiply this by the blend file’s frame rate - this gives me a speed in units per second, you can easily convert this to Km/h, mph, furlongs per fortnight - whatever you want. I get two speeds from now and one frame ago and 1 and 2 frames ago.
To get the acceleration I subtract the previous speed from the current speed this gives me a positive value for increase in speed and a negative value for decrease in speed. I use the abs() (gives absolute value - always positive) tool to make sure it works when the object is traveling backwards towards 0,0,0 i.e distance is reducing, not increasing, otherwise the speed would be negative…
That is what the node tree above does, but some of the expression nodes might be a pain in the ass to remember, so either a script node, or a new “Clockmender Special” Node will be a better alternative, once we agree on how we proceed. The first image shows the speed and acceleration after 68 frames - I am merely moving the cube from 0,0,0 to 50,0,0 over 100 frames - then come back with a 40 frame gap in the middle. Some of the nodes are driving the two text objects to show rounded speed and acceleration - formula is 'Speed: ’ + str(round(x,3)) - this just rounds the speed to 3 sig figs and makes a string of it, adding this to the string “Speed:”
I hope I haven’t over explained this, I don’t know how deep your maths knowledge goes.
Let me know what you think so far.
Cheers, Clock.
EDIT:
I think I may have to multiply the given acceleration by the frame rate as well, since we are dealing in units per second per second, but that is just a minor change I will think on before I do anything more, brain is not working at 100% just yet…