Calculating direction of motion for a Transform

I need to calculate the direction of motion for a transform in a hierarchy, with more precision than taking the delta of the world position between frames. (as the accuracy of this is dependent on framerate) I have a cache of transformation matrices for all of the transforms in the hierarchy per frame so retrieving information from the past is expected.

I don’t know how to account for transforms rotating/scaling and causing non-linear motion in their children and how to propagate this movement to the leaves in the correct way, though I have looked at java - How to calculate tangents of a circle in 3D? - Stack Overflow for calculating the tangent of the circle in 3d space which is working fine.

If the world positions of each leaf transform were plotted on a graph similarly to blender’s motion paths (Motion Paths - Blender 4.3 Manual), then I would basically need the differential of the graph at the current frame.

You can take the delta and make it frame rate independent like so:

    Vector3 velocity = (transform.position - lastPosition) / Time.deltaTime;

I don’t think that this solves the problem:

Take this badly drawn (and simplified) image as an example, the orange boxes represents the child transform at two consecutive frames, with the center darker box being the parent transform. The parent transform has been rotated by ~60 degrees and the child is therefore orbiting the parent. Your solution would give the green arrow (but scaled) where I’m looking for the red arrow (which is a tangent to the circle)

The problems I’m having is when the parent transform has done more than just rotate. It’s scale and position may have changed and to make things more complicated, it may have a parent that is also rotating, giving our dark box a non-linear motion which would in turn affect the motion direction of the orange box

You’ll need to take the previous three positions to extrapolate the next position. I’ve never done this before but caf’s response here seems like a good solution. Ignore the fact that the question is asking about quaternions. The response still applies here.