Я работаю над Unity 3D с плагином ARKit.Переделка стандартной сцены Пример.Моя задача поставить модель дома на самолет (пока еще довольно большой).Но когда я создаю большой объект, он не фиксируется на плоскости и движется вместе с камерой.Что мне делать, чтобы удержать его на месте?При размещении мелких предметов проблем нет.
using System;
using System.Collections.Generic;
using UnityEngine.EventSystems;
namespace UnityEngine.XR.iOS
{
public class UnityARHitTestExample : MonoBehaviour
{
public Transform m_HitTransform;
public float maxRayDistance = 30.0f;
public LayerMask collisionLayer = 1 << 10; //ARKitPlane layer
public GameObject home;
private bool isDetecting;
bool HitTestWithResultType (ARPoint point, ARHitTestResultType
resultTypes)
{
List<ARHitTestResult> hitResults =
UnityARSessionNativeInterface.GetARSessionNativeInterface
().HitTest (point, resultTypes);
if (hitResults.Count > 0) {
foreach (var hitResult in hitResults) {
Debug.Log ("Got hit!");
m_HitTransform.position =
UnityARMatrixOps.GetPosition (hitResult.worldTransform);
m_HitTransform.rotation =
UnityARMatrixOps.GetRotation (hitResult.worldTransform);
Debug.Log (string.Format ("x:{0:0.######} y:
{1:0.######} z:{2:0.######}", m_HitTransform.position.x,
m_HitTransform.position.y, m_HitTransform.position.z));
return true;
}
}
return false;
}
public void Start()
{
isDetecting = true;
}
// Update is called once per frame
void Update()
{
#if UNITY_EDITOR
if (Input.GetMouseButtonDown(0))
{
Ray ray =
Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
home.SetActive(true);
//we'll try to hit one of the plane collider
gameobjects that were generated by the plugin
//effectively similar to calling HitTest with
ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent
if (Physics.Raycast(ray, out hit, maxRayDistance,
collisionLayer))
{
m_HitTransform.position = hit.point;
Debug.Log(string.Format("x:{0:0.######} y:
{1:0.######} z:{2:0.######}", m_HitTransform.position.x,
m_HitTransform.position.y, m_HitTransform.position.z));
m_HitTransform.rotation = hit.transform.rotation;
}
}
#else
if (Input.touchCount > 0 && m_HitTransform != null)
{
var touch = Input.GetTouch(0);
if ((touch.phase == TouchPhase.Began || touch.phase ==
TouchPhase.Moved) && isDetecting == true)
{
var screenPosition =
Camera.main.ScreenToViewportPoint(touch.position);
ARPoint point = new ARPoint {
x = screenPosition.x,
y = screenPosition.y
};
home.SetActive(true);
// prioritize reults types
ARHitTestResultType[] resultTypes = {
//ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingGeometry,
ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
//ARHitTestResultType.ARHitTestResultTypeExistingPlane,
ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane,
//ARHitTestResultType.ARHitTestResultTypeEstimatedVerticalPlane,
ARHitTestResultType.ARHitTestResultTypeFeaturePoint
};
foreach (ARHitTestResultType resultType in
resultTypes)
{
if (HitTestWithResultType (point, resultType))
{
return;
}
}
isDetecting = false;
}
}
#endif
}
}
}