1

I am watching this (game dev, space parenting & rotation) Sebastian Lague video and found that there are three spaces actually (not two) and these are world space, local space and object space.

  1. World space: The static space (0,0,0)
  2. Object space: related to the object space
  3. Local Space: related to the parent of the object

I am amazed that i didn't find the distinction between these two spaces(local and object) on official unity forms but actually it exists. My question is that why there is no Space.Local? I found that there are Space. Self and Space.World. Space.Self is refer to object space. I can move my object to object space using this

    void Update () {
        transform.Translate(new Vector3(0,0,1) * Time.deltaTime * 2,Space.Self);
    }

And i can move my object to world space using this

void Update () {
    transform.Translate(new Vector3(0,0,1) * Time.deltaTime * 2,Space.World);
}

but there is no support for local space that i could move the object to local space (means move the object related to its parent object). There is a fair distinction between Local and Object space but unity didn't consider it i guess or i am wrong.

1 Answer 1

1

In the Unity's inspector, the position and rotation of the Transform component are relative to the parent (defined in the local space)

The axes represented by the gizmo handles are either the global ones (world space) or the object ones as pointed out by S. Lague in the video.

The local axes (axes of the parent Transform) are not represented when you select a gameobject, contrary to other 3D softwares (like Maya I think), and there is no C# function to translate in the local space but you can create one:

Vector3 right     = transform.parent.right;
Vector3 up        = transform.parent.up ;
Vector3 forward   = transform.parent.forward;
Vector3 direction = X * right + Y * up + Z * forward ;

transform.Translate(direction * Time.deltaTime, Space.World);

However, keep in mind that an object A will always have a position and rotation of (0, 0, 0), in object space because the latter is defined by the object itself. An object A can't be moved / rotated from itself.

6
  • "The local axes [...] are not represented when you select a gameobject" You can change from global to local but it's true that you cannot do that in inspector. "no C# function to translate in the local space" Well yes, no "Translate" call, but you can set the transform.localPosition. Also note: Whenever you ask for transform.position - you get the global position, even if the object is deep down in the hierarchie. For directions, there is InverseTransformDirection
    – KYL3R
    Feb 15, 2018 at 9:13
  • No, the local axes are not represented. You can either visualize the global axes or the object axes. You can indeed set the locaPosition, but the OP asked how to set the localPosition using the local (parent) axes .
    – Hellium
    Feb 15, 2018 at 9:25
  • Sorry but i am unable to understand your last paragraph. Can you define it a bit more? Feb 19, 2018 at 4:26
  • setting localPosition or rotation will be happened according to the parent? or object space? Feb 19, 2018 at 4:28
  • The object space is the Euclidian space defined by an object. The origin of the space is the origin of the object. Thus, if you move the object, you also move the origin of the space. The same way, if you rotate the object, you rotate the axes of the object space. Therefore, the object will always have a position of (0,0,0) and a rotation of (0,0,0) in the space it defines.
    – Hellium
    Feb 19, 2018 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.