- Home /
Velocity always reads zero
I can't figure out why every time I try to read an object's velocity, I get 0.
(Yes, the object is moving in my scene.)
Am I doing something wrong here?
public GameObject target;
private float targetSpeed;
void FixedUpdate() {
targetSpeed = target.rigidbody.velocity.magnitude;
Debug.Log("Velocity: " + targetSpeed);
}
Comment
How are you moving the object? If you're changing the transform directly, it won't register any velocity. Velocity only comes into play when you move things physically - when the object has a rigidbody attached and you use things like forces or setting velocity directly to move them.