Raycaster returning incorrect intersection point


I have a task where I have to create a Ray at an arbitrary origin with a direction to find the intersection with the terrain below and also find the intersection point there.

To explain in simplest possible terms, I created this example on jsfiddle.


I have a vector with the origin at the top of the BoxGeometry going towards the negative z-axis here. Although the intersections are good (i.e the ray intersects with every plane geometry below), the distance to these plane meshes and their corresponding intersection points do not seem right.

Seems like it returns a value approximately equal to (0,0,0) as a point of intersection for every plane mesh above. Is there something to do with the world matrix here?

What am I doing wrong here? Any help would be appreciated.


Are you aware that you ray does not only intersect with the planes but with the box and the arrow helpers? I’ve changed the code so it only works with terrainGroup. Besides, when have to update the world matrices of your planes once if you transform them and want to raycast right after their creation. Normally, the renderer updates the world matrices for your but in this case it’s your task.


Aha. All I had to do was to update the matrixWorld right after their creation. Thanks for this. It works.