Local Space Vs. World Space in Unity!

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!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store