2
votes

I'm new to ARKit and I imported Unity ARKit Plugin from the Unity Assets Store, I loaded UnityARKitScene to the scene, and replaced the hitcube GameObject with my prefab asset. I can run the project on my device, but the model which I imported can be placed not only on surfaces but on the 'air' too.

Is there anything that I need to change to make place the model on plane surfaces only?

Thank you.

1
When I was confronted with the same question I chose to use the plane detection mechanism from the Apple ARKit Example. Download at: github.com/gao0122/ARKit-Example-by-AppleKingalione
You can try to use only ARHitTestResultTypeExistingPlaneUsingExtent as an acceptable result of HitTest. It seems to be the most accurate type of hit result.obywan
@Kingalione but the project in the git repo is not unity right?zb22

1 Answers

0
votes

In UnityARHitTestExample.cs just change the following code

// prioritize reults types
ARHitTestResultType[] resultTypes = {
    ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
    // if you want to use infinite planes use this:
    //ARHitTestResultType.ARHitTestResultTypeExistingPlane,
    ARHitTestResultType.ARHitTestResultTypeHorizontalPlane,
    ARHitTestResultType.ARHitTestResultTypeFeaturePoint
};

To this

// prioritize reults types
ARHitTestResultType[] resultTypes = {
    ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
    // if you want to use infinite planes use this:
    //ARHitTestResultType.ARHitTestResultTypeExistingPlane,
    //ARHitTestResultType.ARHitTestResultTypeHorizontalPlane,
    //ARHitTestResultType.ARHitTestResultTypeFeaturePoint
};

For more info check https://developer.apple.com/documentation/arkit/arhittestresult.resulttype