Jump to content

Issue with ray casting from nested camera and rotation


FlashyGoblin
 Share

Recommended Posts

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! :)

Link to comment
Share on other sites

  • 1 year later...

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