I am running on Android. I have a program where I place a plane on the floor in an AR application at the location of a placement indicator (placement indicator follows AR planes and is placed based on a raycast from the center of screen)
Since I cannot guarantee that the plane will be placed with no rotation I can’t guarantee that a Vector3.up is the normal of the place. How do I get the normal to the plane?
placedPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);
placedPlane.transform.SetPositionAndRotation(placementIndicator.transform.position, placementIndicator.transform.rotation);
debugLog("placed plane's rotation: " + placedPlane.transform.rotation);
Plane planeComponent = placedPlane.GetComponent<Plane>();
Vector3 normal = new Vector3(planeComponent.normal.x, planeComponent.normal.y, planeComponent.normal.z);
debugLog("plane's normal vector: " + normal.ToString());
I have created a debug “console window” at the bottom of the screen. debugLog(string) simply add that text to a new line in its scrollview.
The first debug log reports back a non zero rotation, which is not surprising because AR planes are not going to be perfect.
The second debug log gives a (0,0,0) value for the normal vector always.
An example output is:
placed plan’s rotation: (0.0, -0.9, 0.0, -0.4)
normal vector: (0.0, 0.0, 0.0)
My guess is that I am grabbing the Plane component incorrectly, because a normal vector should at least have some value somewhere. And as far as I can tell you can’t check if you failed to get a Plane object with getComponent because you can’t check a Plane object == null.
How should I get the normal vector of a plane?