Search the Community
Showing results for tags 'ray casting'.
Found 3 results
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!
I'm trying to attach the ray I put in my scene to my active camera so I can move around the camera and have the ray hit whatever my camera is looking at. I've been able to get the ray into my scene, and have it hit something, but haven't been able to figure out how to attach it to my camera so it follows it. My best attempt was trying to create a box, attach it my camera as it's parent and then attach the ray to that box using rayhelper.attachtomesh but my ray is no longer visible when doing this. Any help please.
Hi everybody, I have another question for the brain trust. I am working on a plane game. I am able to control my plane perfectly fine and I have replicated the plane class to create enemy planes. The question I have is what is the best way to efficiently create a simple AI system for the enemy planes? Here is what I was thinking: I attached a screen shot of a plane with some lines to demonstrate what I was thinking. There would actually be 9 lines total but I am showing on 3 lines. If I detect an "obstacle" mesh via the right rays, then I would have the plane move left and conversely for the opposite. If I detect an "player" mesh on any of the rays, then I would rotate and fly towards the plane. I have played with simple line meshes to do the same thing but I was worried it could be less efficient if I had a large collection of obstacles and players objects to loop through to detect a collision. Any thoughts would be greatly appreciated!