Jump to content

moveToVector3 on a control. how to make it work?


Jouerose
 Share

Recommended Posts

Hi Jouerose !

Don't know mush about GUI, but from what I understand :

  • linkWithMesh makes your Control link to a mesh, so the control position in 2D is recomputed each frame as the position in 2D (projection) of the mesh changes at every camera move.
  • moveToVector3 makes your Control at a given 3D position, so 2D projection when you call it and do nothing at next camera moves.

I think your camera, or scene, is not ready in your playground, that's why the projection of your Vector3 is not well computed and is set to (0,0,0).

With executeWhenReady, you can see that your moveToVector3 is working.. but it doesn't update your 2D position when camera moves : https://www.babylonjs-playground.com/#XCPP9Y#524

If you want to have to same behaviour as linkWithMesh, you may use a moveToVector3 each frame : https://www.babylonjs-playground.com/#XCPP9Y#527

Or you can create a mesh, set its absolute position and disable it. Maybe a bit heavier but may be easier to understand, using this "pivotMesh" as 3D pivot for your Control

Link to comment
Share on other sites

7 hours ago, SinhNQ said:

Hi,

Welcome to the Babylon.js's forum ?

Before use moveToVector3 method you must call scene.updateTransformMatrix() function.

https://www.babylonjs-playground.com/#XCPP9Y#526

I don't know why but i have encountered this problem. @Deltakosh or someone will explain to you.

Thank you very much @SinhNQ for your help. 

I also wish @Deltakosh tell us more about it.

Link to comment
Share on other sites

7 hours ago, Amarth2Estel said:

Hi Jouerose !

Don't know mush about GUI, but from what I understand :

  • linkWithMesh makes your Control link to a mesh, so the control position in 2D is recomputed each frame as the position in 2D (projection) of the mesh changes at every camera move.
  • moveToVector3 makes your Control at a given 3D position, so 2D projection when you call it and do nothing at next camera moves.

I think your camera, or scene, is not ready in your playground, that's why the projection of your Vector3 is not well computed and is set to (0,0,0).

With executeWhenReady, you can see that your moveToVector3 is working.. but it doesn't update your 2D position when camera moves : https://www.babylonjs-playground.com/#XCPP9Y#524

If you want to have to same behaviour as linkWithMesh, you may use a moveToVector3 each frame : https://www.babylonjs-playground.com/#XCPP9Y#527

Or you can create a mesh, set its absolute position and disable it. Maybe a bit heavier but may be easier to understand, using this "pivotMesh" as 3D pivot for your Control

Thank you for your comments @Amarth2Estel

Link to comment
Share on other sites

Quote

Before use moveToVector3 method you must call scene.updateTransformMatrix() function.

This is because the scene was not yet rendered and thus the view and projection matrices are not set on the scene :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...