Jump to content

Detect if camera looking at object


Light
 Share

Recommended Posts

Good day.

I'm working in small proyect using babylon.js, it's so great, but im having some troubles. 

1) How do i detect if im looking directly to an object? I try to search for options and found on playground a solution to make a line from camera and detect a collition with line and object. But its not the best solution can you help me with this? And not working well sometimes, because of VR camera distortion. And line have alpha at 1 but i still can see it.

lines = BABYLON.Mesh.CreateLines("lineMesh", [
            new BABYLON.Vector3(0, 0, 0),
            new BABYLON.Vector3(0, 0, 3000)
            ], scene);
            lines.material.alpha = 1;
            lines.parent = camera;

sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 100, scene);
sphere.position=new BABYLON.Vector3(300,-400,-500);

if(lines.intersectsMesh(sphere, true)){
console.log("you found me");
}

2) I have an object flying slowly around me sometimes when it on top of me or below me in Y=0, it disappears or start to flashing if im looking at it until its not around Y=0.

3) I'm using VRDeviceOrientationFreeCamera if I have distortion at 0 it's OK but if I change it, it's bacame too laggie. Is there any solution? 

 

Thanks for all possible help.

Sorry for my bad English. 

Link to comment
Share on other sites

Hi Light,

 

you could use the scene.pickWithRay function for that. It fires the predefined ray (in your case a ray in the camera's direction) and checks if it collides against the meshes define din the predicate. It returns  a PickingInfo object that contains all the info you need about the collision point.

You can see how it works in this cool example (that is not made by me! I just found it) - http://www.babylonjs-playground.com/#1BAPRM#68

 

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