how to get velocity of object unity code example
Example 1: unity get velocity of gameobject
Rigidbody rb = GetComponent<Rigidbody>();
rb.velocity;
Example 2: unity how to get the side ways velocity of a object
Rigidbody rb = GetComponent<Rigidbody>();
Vector3 worldVelocity = rb.velocity;
Vector3 localVelocity = transform.InverseTransformVector(worldVelocity);
Example 3: unity how to set rigidbody velocity
Vector3 velocity = new Vector3(10f, 10f, 10f);
GetComponent<Rigidbody>().velocity = velocity;