FlashyGoblin Posted April 14, 2016 Share Posted April 14, 2016 Hey everyone. I'm having a bit of trouble figuring out ray casting when the camera's parent is set to a mesh. I exhausted Google search and I'm hoping someone as some insight. Here's the scoop. I have a car that drives around a scene. I also have a FreeCamera that's parent is set to the car. The camera's position is set just above the car so you can see the front of it. (As if you placed a GoPro on the roof). I want the user to be able to rotate the camera in all directions to see around the car as it is driving (you can look out the back side as the vehicle drives forward). The rotation of the camera does not set the direction of the car. I am using scene.pickWithRay() with a reticle in the center of the camera. Everything works great when driving forward, until the car rotates it's direction. Then my ray is offset by that rotation. I'm not sure how to correct the offset when defining the ray. Here is how I'm currently defining the ray within my render loop... var ray = new BABYLON.Ray(camera.position.add(camera.parent.getAbsolutePosition()), camera.getTarget().subtract(camera.position).normalize()); Any ideas would be greatly appreciated. Thanks so much! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 14, 2016 Share Posted April 14, 2016 I would say: var ray = new BABYLON.Ray(camera.globalPosition, camera.getTarget().subtract(camera.globalPosition).normalize()); Quote Link to comment Share on other sites More sharing options...
FlashyGoblin Posted April 15, 2016 Author Share Posted April 15, 2016 That worked! Thanks again!! Quote Link to comment Share on other sites More sharing options...
none-9999 Posted May 12, 2017 Share Posted May 12, 2017 please, full code.. Quote Link to comment Share on other sites More sharing options...
none-9999 Posted May 12, 2017 Share Posted May 12, 2017 solved for me Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.