Reputation: 86
how to get Rigidbody2D velocity magnitude x.I tried this code.
Rigdbody.velocity.magnitude.x
But it doesn't work.
Upvotes: 1
Views: 2714
Reputation: 983
According to the Unity Docs, Vector3.magnitude
is a float
. You are trying to access it like it's a Vector3
. In other words, Vector3.magnitude
does not have a variable x
.
Another issue I see is that you have a spelling mistake in Rigdbody
. If that is the variable name, you should change it to prevent future confusion and rage. Typically, a c# variable should start with a lowercase letter likeThis
After taking these both into account, your call should look like this:
float magnitudeX = myRigidbody2D.velocity.x;
or
float magnitude = myRigidbody2D.velocity.magnitude;
Upvotes: 1