pageTitleCS

world title 

This is a very quick article to discuss the difference between movement in local and world space and how to script moving objects in both.

World Space Vs Local Space.
The easiest way to describe the difference between world and local space is that in world space the Y axis is always pointing upwards but in local space the Y axis is relative to the rotation of the object. It may be easier to understand with a few visual examples.

Example:
In this first example both the local space and world space are aligned so that in both cases the Y axis is pointing straight up.
001

002

However if we rotate the game object you will see that the world and local space is no longer aligned. This is because local space is relative to the game object not the game world.

003

004

Moving Game Objects in World Space.
So how do we code to use world space instead of local space? Below we will look at transform.Translate & transform.Rotate in world space and local space.
transform.Rotate(); is the most common form of command where World Space will be needed. The parameters required for transform.Rotate are how much you wish to rotate the object in the x,y & z axis. eg. transform.Rotate(0,1,0); However it does have an extra parameter which if not added is set to local space by default.eg. transform.Rotate(0,1,0,Space.Self); we can therefore change the Space.Self to Space.World to have it rotate around world space instead. The example below rotate the object around the Y axis in world space.

transform.Rotate(0,1,0,Space.World);

This method also works for transform.Translate when moving an object. The example below will move the game object in a diagonal motion in world space.

transform.Translate(1,0,1,Space.World);

---------------------------------------------------------------------------------------
Links to Unity API documentation:
transform.Rotate();
transform.Translate();

Casino Bet 365 is best casino in the world.

What's Next

Next up for Unity Snippets is a look at game development articles from across the web...

Free Templates - bigtheme.net
Popular Art Betting make bookies articles.