how to get the velocity of an object in unity code example
Example 1: unity get velocity of gameobject
Rigidbody rb = GetComponent<Rigidbody>();
rb.velocity; // Velocity of gameObject (Vector3)
Example 2: how to get rigidbody speed in unity
var speed = rigidbody.velocity.magnitude;
Example 3: unity how to get the side ways velocity of a object
Rigidbody rb = GetComponent<Rigidbody>();
Vector3 worldVelocity = rb.velocity;
Vector3 localVelocity = transform.InverseTransformVector(worldVelocity);
//This gives velocity in all directions sideways is on the x axis the thread gives more info