I’m making a simple car driving game.
I’m trying to display forward velocity on screen.
…But both rigidbody.velocity.z and transform.InverseTransformDirection(rigidbody.velocity).z return the same value. They both go negative when I turn the car around.
What am I doing wrong?
Thanks in advance!
public class UIManager : MonoBehaviour
{
public GameObject car;
Rigidbody carRb;
public Text stats;
public Text stats1;
private void Start()
{
carRb = car.GetComponent<Rigidbody>();
}
private void Update()
{
Vector3 worldVelocity = carRb.velocity;
Vector3 localVelocity = transform.InverseTransformDirection(carRb.velocity);
stats.text = "World Velocity Z: " + Mathf.Round(worldVelocity.z * 36)/10 + " Km/h";
stats1.text = "Local Velocity Z: " + Mathf.Round(localVelocity.z * 36)/10 + " Km/h";
}
}