Raycast from one mesh to another one

Recommended Posts

Hi, I'm trying to create a ray from one mesh to another one, but I have problems with the direction.

I'm using this one:

var ray = new BABYLON.Ray();
var rayHelper = new BABYLON.RayHelper(ray);
var localMeshDirection = new BABYLON.Vector3(-1, 0,0);
var localMeshOrigin = new BABYLON.Vector3(0, 0, 0);
var length = 20;
var door = scene.getMeshByName("shop08");
rayHelper.attachToMesh(door, localMeshDirection, localMeshOrigin, length);
In the above case I have a ray on the -x axis, but I need to use the direction of a specific mesh, basically when the user click on any mesh the ray will check for collisions in between. 
How can I get the direction of a specific mesh and include it on the rayHelper.attachToMesh ?
Thanks for your valuable help.

Share this post

Link to post
Share on other sites

Hi, I figured out :) :


now I need to see the collision :)

function myRay(){
var door = scene.getMeshByName("mesh1");
var punti= scene.getMeshByName("mesh2");
var origin = door.position;
var forward = punti.position;       
var direction = forward.subtract(origin);
direction = BABYLON.Vector3.Normalize(direction);
var length = 20;
var ray = new BABYLON.Ray(origin, direction, length);
let rayHelper = new BABYLON.RayHelper(ray);     

Share this post

Link to post
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.

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.


  • Recently Browsing   0 members

    No registered users viewing this page.