Local vs World position

Benjamin Calvin
3 min readSep 18, 2022

--

Understanding the differences between local and world positions can save a lot of frustration when designing in any environment. These are small things you should be situationally aware of.

The images below are an example where local and world positions are the same. The gameobject’s local position is the red box and coordinate icon on the gameobject itself while the red box on the right represents the world position.

What if I wanted to rotate it? Now the Y is the Z and Z the Y. Now when dealing with animations, coding, and many other aspects you have to remember to adjust to the change.

There is a simple solution, put the gameobject into a parent that matches the world position.

Create an empty child gameobject in the gameobject with alignment issues so it matches the coordinate position as the gameobject and called it bunnyparent. Move it outside of the gameobject into the main Hierarchy. Then ensure all Rotation X,Y,Z are 0. We are leaving the position points the same because we want to be the same current world position as the bunny.

To provide some coding context. I am using Vector2 values pulled from the InputManager, I am not using Y on a Vector3.

Update()
{
x = InputManager.Instance._Vector2Movement.x;
y = InputManager.Instance._Vector2Movement.y;
transform.Translate(new Vector3(x, 0, y) * Time.deltaTime);
}

Here is code for the bunny pulling input from the InputManager class. The first animation is with the parent class, with the script attached to the parent class. The second animation is without a parent class where Z is acting like Y.

Thanks for reading.

--

--

Benjamin Calvin

Dedicated and motivated individual learning programming and sharing my discoveries with you.