# Parent

## Recommended Posts

Hi people. I have a new question. It is a noob question, but i searched for the answer, but I didn't find it.

If I have a house for example, and all walls are separate objects, and the floor too.

The floor world position is (10,0,10). The floor is the parent of walls. Walls world position show me (0,0,0), and walls._absolutePosition show me (10,0,10) for all walls. And the question is )

How can I determine the world position of walls?, One should have (20,0,10), other (10,0,20). But I can't determine this values. Should I get position of floor, floor scale, and then take the position of walls?

##### Share on other sites

Hi,

All questions are good questions!

To get the absolute position of an object use its getAbsolutePosition() method. It's deliver the world position of the object. You might need to force a new computation of the world matrix if it didn't work correctly.

##### Share on other sites

Or you can add the parent position to the children position :

`absolutePosition = parent.position.add(wall.position);`
##### Share on other sites

Ok.

I have this piece of code:

`.....box.position = new BABYLON.Vector3(10,0,10);for(var i in m){   m[i].position = BABYLON.Vector3.Zero();    m[i].parent = box;    m[i].computeWorldMatrix(true);      console.log(m[i].getAbsolutePosition()) return vector Zero (0,0,0) for all meshes   console.log(m[i]._absolutePosition)    return box.position for all meshes   console.log(m[i].position)    return vector Zero (0,0,0) for all meshes}`

I have to apply matrix result from computation to meshes world matrix?

Or what I'm doing wrong? )

A possible cause, is because all meshes have their pivot, is not the same for all?

Thanks

##### Share on other sites

Except for the first one, the results are correct. The meshes' positions are all 0,0,0. They're absolute position is the box's position.
I find it odd that getAbsolutePosition return a different result than _absolutePosition, as the function is simply a getter to the value (https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Mesh/babylon.abstractMesh.ts).
Want to create a simple demo in the playground so we can debug it together? I have created a quick demo - http://www.babylonjs-playground.com/#19B7X0 , check the console showing the before and after position of all selected meshes, you will notice they all include the box's position. Try computing the world matrix of the box after changing its position, might solve the problem.

##### Share on other sites

Thanks you both.

Computing the world matrix of the box after changing its position solve it. I can't explain why

##### Share on other sites

• 9 months later...

why do we have to manually force computation of the worldmatrix?

Quote

You might need to force a new computation of the world matrix if it didn't work correctly.

Is there some documentation about it?

I wanna know when I have to do it manually and when not. (without trial and error)

Update:
I just found it.

The renderId is responsible. (so once per frame - without additional check for translation)

##### Share on other sites

The only reason to force a worldMatrix computation is when you need it before the next frame.

World matrices are updated on every render

##### Share on other sites

5 minutes ago, Deltakosh said:

The only reason to force a worldMatrix computation is when you need it before the next frame.

World matrices are updated on every render

Yep thanks

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.