Converting a vector from world space to local space, and vice versa, in blueprint

This seems like such a common and useful operation that I thought there would be an inbuilt function, but apparently not. What is the easiest way to achieve both of these tasks? I did search and came up with nothing. I have figured out a way, which I posted below, to convert a local vector to world space, but have not tackled the opposite direction, and have not taken into account scaling as I don’t need it yet.

Transform Location seems to take care of local to world.

3 Likes

First substract actor position with base of new local space and result rotate to inverted rotation of the base

1 Like

I have been shown the “Inverse Transform Location” node which converts a vector from world to local space, now I just wonder if there is a more efficient method than above for converting from local to world.

To translate a local vector to a world vector, rotate a vector according to the object’s rotation.
To translate a world vector into a local vector, rotate the vector according to the object’s invert rotation.

3 Likes

also use “Inverse Transform Location” to convert world to local.

1 Like

Took me a moment to find what Oneiros86 was talking about. Here’s a screenshot if anyone needs it.
The “Location” input node on Transform Location is where you put the position in local space and the “Return Value” is where that position is returned after being transformed into world space.

273151-capture.png

13 Likes

This seems to work for me.

Incase some one need it:

FVector WorldLocation = FVector(100, 100, 0);
FTransform WorldTransform = GetTransform();|
FVector LocalLocation = WorldTransform.InverseTransformVector(WorldLocation);

8 Likes