Check out example codes for "check velocity is forwards or backwards + unity". It will help you in understanding the concepts better.
Code Example 1
//moving forwards
Mathf.Abs(localVelocity.z) > 0.01f
//moving backwards
Mathf.Abs(localVelocity.z) < 0.01f
Learn ReactJs, React Native from akashmittal.com