Get horizontal velocity of an object
how can i set float x for example for only the horizontal velocity of an object? in C# btw
Comment
Answer by Chikari · Feb 13, 2017 at 02:28 PM
Vector3 tempVector = GetComponent<Rigidbody>().velocity;
tempVector.x = 10f;
GetComponent<Rigidbody>().velocity = tempVector;
Answer by UnityCoach · Feb 14, 2017 at 12:32 PM
If what you want is to "read" the horizontal velocity of an object, you may simply cast it to a Vector2.
((Vector2) GetComponent<Rigidbody>().velocity).x