3D Survival FPS Game
Understanding World space and Local Space
In this article we will focus on understanding what local space and what world space is, and how to change each value into the other, along with fixing the character movement to match the camera position.
World Space vs. Local Space:
In a more similar approach to understanding what they are and how they differ is to visualize them as folders. World space is the encompassing big folder that can place anywhere within the desk/organizer or drawer. It is the folder compared every single object within the scene. Local space is the files within that folder. The arrangement to file size to file content is only ever compared to the contents within the folder.
The best example of this is the current player movement, now that our camera rotation follows the mouse movement, we can freely rotation our line of view to any degrees, but once we start moving be it forward or sideways the movement doesn’t follow the camera angle.
So even if I am facing right and I press the forward button, I still go forward instead of right. This is because the player movement is within the “World Space” setting while the camera movement was set to the local space. Therefore the player movement is not sync with the mouse movement.
What needs to occur now is within the player movement method, we need to convert the world space Transform value into a local space value. Lucky within the Unity API there is such a public method called “Transform Direction”.
Simply put, we are going to make a conversion within the player movement method. Just before we assign the character controller to move, we are going to add in the direction variable to convert to a world space value.
With this simple conversion we are now able to properly direct the player movement to the camera position.