How would I go about converting a direction from Global space to Local space?

Attention Topic was automatically imported from the old Question2Answer platform.

Hello,

So I am trying to get a `RigidBody3D`’s linear velocity, more specifically, get the Z component of that so I can get my forward/backward speed. This works great… unless my `RigidBody3D` is rotated. Then the farther I rotate towards east/west, the less of a factor my Z component plays in telling me my forward speed.

How would I go about converting `linear_velocity` from a global direction to local one so I can always rely on the Z component of it being my forward velocity?

Thanks.

I think your question is a way to access the length of the velocity.
Simply, Vector3().length().
The Vector3 is your velocity vector.
This can give you the magnitude of your velocity which I assume is the “local z” you needed.
``````linear_velocity.rotated(Vector3.UP, -rotation.y).z
If this causes any bugs I’ll be sure to try `Vector3.length()`. Again, thanks!