# What exactly does Object3D.getWorldPosition() returns?

It is said that .getWorldPosition() `Returns a vector representing the position of the object in world space.` Is the returned position the centre of the 3D object? If so, how can we get the world position of a point in the object ?

1 Like

The difference between `.position` and `worldPosition` is that `object.position` represents â€ślocal positionâ€ť of the object - his position in his so called â€ślocal spaceâ€ť.

The reason there is a difference is because an objectâ€™s position is not only influanced by itâ€™s `.position`, but also the `.position` of itâ€™s parent. In Three.js you create parent-child relations with

` parent.add( child );`

Now `child` object is a child of the `parent` object. Children become sort of â€śattachedâ€ť to the parent - not emotionally, but in relation to itâ€™s transform (objectâ€™s transform is itâ€™s scale, rotation and position).

It might seem confusing, but think of it this way:

• There is a mother who is pregnant - `mother.add( child );`
• She carries the child in her belly. The mother walks 10 steps to the right - `mother.position.set( 10, 0, 0 );`
• Now the childâ€™s world position will be `(10, 0, 0)`, BUT itâ€™s local position - `child.position` - will be `(0, 0, 0)`, because the child itself did not move
It was â€śattachedâ€ť to the mother and SHE carried it over 10 steps to the right.
• The same happens with 2 other transform properties - scale and rotation. If the mother starts spinning around `mother.rotation.y += 3;` the child will also rotate.
If a piano falls on the mother she will get squashed - `mother.scale.y = 0.1;` - and the baby will get squashed as well . The childâ€™s world scale will be `(1, 0.1, 1)`, but itâ€™s local scale - `child.scale` - is still `(1, 1, 1)`.
• Parents can be chained , so
`mother.add( child );`
`car.add( mother );`
`scene.add( car );`
Now the mother is in the car, so if the car moves 100 steps to the left, the motherâ€™s and the childâ€™s world positions will change to `(-100, 0, 0)`, but only the carâ€™s local position - `car.position` - will be `(-100, 0, 0)`.

Okay, so thatâ€™s world position.

Is the returned position the centre of the 3D object?

You can say that, but really itâ€™s just an abstract point in 3D space, which represents itâ€™s world position, so it wonâ€™t necessarily be the exact center of itâ€™s volume or geometry.

If so, how can we get the world position of a point in the object ?

I think that depends on your use case. Hard to guess what you mean by just â€śa point in the objectâ€ť.

5 Likes

Hey your explaination on parent-child relation felt like icing on the cake. kudoos to that

What I meant is that I have a 3D object,say, a cube. At a specific point,say, on the center of one of its face,. I need to attach another object. So I need to know some properties of that point(center of one of the face of the cube), right?. I thought knowing the coordinates(position , not to confuse) of that point will make it easier to attach the objects.

Thanks, itâ€™s not something parenting books would teach you.

It sounds like your objects could use parent-child relations. What you wanna do first is put the parent at position `(0, 0, 0)` and find the offset position for the child. Letâ€™s say the position, where you want to attach the second object is 1 meter to the right of the main object. Then you would do:

``````mainObject.add( secondObject );
secondObject.position.set(1, 0, 0);
``````

Aaaand you have an object attached to your main model, with an offset of `(1, 0, 0)`.

Feel free to use the Three.js Editor to experiment around with that. You can parent objects there, by dragging the childâ€™s name onto the parentâ€™s name in the scene graph outliner.

I tried doing it, but then scaling problem pops up When I add 2nd object as child of 1st object, 2nd object is too tiny to be visible on the scene