Transform a vector from local space to world space

Suleiman Abdullah
2 min readMar 7, 2024

Objective: Transform a vector from local space to world space.

In the first step create an empty object with new script called Transformation.

Create a Vector2 variable localCoord ,then use Gizmos to draw circle in this Vector2.We use Gizmos this to visualize the local position.

Note :OnDrawGizmos interprets all your input in world space by default, and so whatever coordinate you pass into it, it will be interpreted as a world space position.

Remember this local coord will be in local coord ,if we don't use Gizmos.

Create return method ,which return a Vector2 and pass a Vector2.

We need to transform a vector from local to world coordinate,we do this by assign our position equal to x axis of local coord multiply tranform.right. Then assign position equal to y-axis of local coord multiply transform.up. Lastly we return the position .

Go to OnDrawGizmos method ,set local vector2 variable and assign it to the LocalToWorld method which will pass localCoord variable. Lastly pass worldPos as parameter on Gizmos.DrawSphere.

This is how to transform a Vector from local to World.

Note: I know it can be confusing go Freya Channel watch solution, but you will need to learn about linear algebra in first chapter for game.

here a link : https://www.youtube.com/live/fjOdtSu4Lm4?si=7awHhLa63xFn26nd

--

--

Suleiman Abdullah

Self taught Unity Developer, who is passion about making games ,and he loves Math For Game Development