# How can i determine the direction of a plane from hit-test results?

How can I determine which plane it is based on the hit test results? That is, floor, wall, or ceiling. Or is it horizontal or vertical?

There should be a get normal at hit point method. I forget it’s actual caller though. Take a look at the pickInfo section of the API and see if you can find something about getting the normal in that. Pretty sure it’s there. I’m on my phone or I’d grab it for you.

I found such a solution, I don’t quite understand matrices and their transformations, but it gives at least some results.)

`let vector = BABYLON.Vector3.TransformNormal(BABYLON.Vector3.Up(), hitTest.transformationMatrix).normalize();`

If hitting the floor then y = 1, if the ceiling is y = -1. If the wall, then everything else.
How correct is this?

This is correct if floor/ceiling are horizontal. You should however not check for 1/-1 but for `1 - epsilon < y < 1 + epsilon` and `-1 - epsilon < y < -1 + epsilon` (epsilon being a small number like 0.0001) because of rounding errors in computations.

Thanks, I’ll keep that in mind.

There is

``````pickInfo.getNormal(useWorldCoordinates?: boolean, useVerticesNormals?: boolean)
``````

If you want to simplify finding that normal.

Also you can do
BABYLON.Vector3.Dot(normal, direction) and then take the smallest of the results to figure out what surface direction its closest to.

https://playground.babylonjs.com/#HXQVZN

pickInfo.getNormal(useWorldCoordinates?: boolean, useVerticesNormals?: boolean)

I tried this on hit test results but got errors. Hit test has matrix and this method not work. I have to get normal from the matrix.

What process are you doing to get your pick info? You say hit test but there are a bunch of way to do a hit test. Its hard when we dot know your method. Are you using a ray, a pointer interaction etc?

Is this for webXR, if so then my bad I thought you were just trying to get like a ray pick or soemthing.

Yes, this is for webXR.

``````xrTest.onHitTestResultObservable.add((results) => {
if (results.length) {
hitTest = results[0];
}
});``````