how would I check for an object's velocity.magnitude on one axis?

for some very odd reason, the ball’s rotation on the y axis is always changing however the ball doesn’t move because of this so it wouldn’t affect my game

I either want to be able to set the ball’s rotation to zero on all axis or just declare s as the ball’s x axis. to set the rotation to (0,0,0) I still need to know how to find out how to check for the object’s velocity.magnitude on either the x or z axis, so how would I do that?

s = GetComponent<Rigidbody> ().velocity.magnitude;

this is the code I have been using and it works but as I said I now wanna be able to check for the object’s velocity.magnitude on one axis

I tried adding .x to the end of the code like this:

s = GetComponent<Rigidbody> ().velocity.magnitude.x;

but I just get an error, so if someone could help me out, that’d be great thanks :slight_smile:

velocity.magnitude is the length of a vector, so the “magnitude” of one axis is the x/z/y value of the vector

Also, you can check the speed not only in the direction of the coordinate axes, but in any arbitrary direction by using the dot production.

        Vector3 direction = // an arbitrary direction (any normalized vector)
        float speedInThatDirection = Vector3.Dot(rigibody.velocity, direction);
1 Like

I don’t quiet understand what’s your issue with the ball rotation. Could explain it a bit more?