I usually only work with 3d physics but I guess this is the same with 2D in godot.
Transforming a 3d vector from global to local space works via the xform and xform_inv from the Node2D (i.e. a RigidBody2D).
https://docs.godotengine.org/en/3.1/classes/class_transform2d.html?highlight=transform2d
To convert a vector (rotation only) from local to global you would use global_translate.basis_xform(someXY)
.
That is helpful if you have a local force (i.e. rocket thrust "forward") and want to transform this into a global force vector for apply_force
. You can also use global_translate.xform
if you want to convert not only the rotation but also the local translation to a global value (that can be tricky though because add_force requires a relative offset in global space not a global position).
To your question:
global_translate.basis_xform_inv(someGlobalDirection)
should transform a global vector back into local space.
So you can get i.e. the objects local "forward" velocity from a global velocity vector.