Local Space Vs. World Space in Unity!

addam davis
2 min readJan 17, 2022

--

Objective: Change the player from local space to world space!

In the last tutorial we created a camera controller. Now, our player looks where the mouse is located. Unfortunately, our player is moving in the local space. This means while holding the W key the player moves “forward” and if we look to the left “forward” doesn’t change.

We want to change the player to using the world space. This will make it so the player’s “forward” movement will always be where they are looking. We can accomplish this with a small amount of code. Open the player’s script.

Inside the method where we calculate the movement, after we calculate jump and gravity, we assign velocity to transform direction. Transform direction changes local space to world space, and the direction we are changing is the velocity.

That’s all it takes. Now our player will move towards the camera as they traverse the 3D world. In the next tutorial we are going to talk about camera sensitivity. I’ll see you in the next tutorial!

--

--