Jump to content

[SOLVED] - place mesh in the center of the camera view


nogalo
 Share

Recommended Posts

Hi.

I am visiting this forum a lot because i recently started working on several projects using babylon.js  am absolutely in love with it. This is my first post/question ever tho and I hope you can help me.
Also, I put "VirtualStoreProject" in the name because I believe I will have a few more questions during this so I want to 

I started working on Virtual Store project, and I created proof-of-concept page just to try some things out before going into the real work. Here is a link to that (looks awful at the moment I know)
https://www.productexample.com/virtualStore/virtualStore.html

Now what I want to achieve is when I click on the mesh, that mash moves toward the center of the camera view. For now the implementation is not very fancy 


targetPosition = new BABYLON.Vector3(camera.position.x+20, camera.position.y, camera.position.z);


and this only looks okay if you are looking straight at the mesh and you are not too close to a wall in front of you (in case you do, the mesh goes outside). 

Another question I want to ask is if there are some TriggerVolumes (as they are called in Unreal Engine 4) inside Babylon. So that i only can use some inputs and interact with meshes when I am inside that volume. I've kinda implemented this in the demo using the distance between the active camera and the hit after scene.pick()  method. 

 pickResult = scene.pick(scene.pointerX, scene.pointerY);
 currentMesh = pickResult.pickedMesh;
 if (!currentMesh.name.toLowerCase().includes("env") && pickResult.distance < 80) 

but I am not sure if that is good solution for this project.


Thank you all for the help. I hope you have a good day. 

Link to comment
Share on other sites

Hi @nogalo welcome to the forum!  

 

If you want to move the object towards the center of the camera view, you can try calculating a position from the camera position added to a  scaled camera forward vector, like this playground: http://playground.babylonjs.com/#BIYF2R#2

You of course would have to take into account distance from walls, etc.

As for trigger volumes, @aWeirdo had a good suggestion in this issue if it works for you: 

 

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...