Hi,
I use AR foundation and ARKIT and IPAD with LIDAR on unity 2020.3.13f1.
How to prevent drift of gameobjects on the mesh.
First image I instantiated some sphere and continue to scan the place. After going back to my initial position sphere drifted a lot. Why this is moving ?
the update function:
if(isActivate)
{
if(Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
Debug.Log("Touched the UI");
return;
}
touchPosition = touch.position;
if(touch.phase == TouchPhase.Began)
{
Ray ray = origin.camera.ScreenPointToRay(touch.position);
RaycastHit hitObject;
if(Physics.Raycast(ray, out var hit, float.PositiveInfinity, 1 << meshManager.meshPrefab.gameObject.layer))
{
lastSelectedObject = hit.transform.GetComponent<PlacementObject>();
if(lastSelectedObject != null)
{
PlacementObject[] allOtherObjects = FindObjectsOfType<PlacementObject>();
foreach(PlacementObject placementObject in allOtherObjects)
{
placementObject.Selected = placementObject == lastSelectedObject;
}
}
}
}
if(touch.phase == TouchPhase.Ended)
{
lastSelectedObject.Selected = false;
}
}
for (int i = 0; i < Input.touchCount; i++)
{
var touch = Input.GetTouch(i);
var ray = origin.camera.ScreenPointToRay(touch.position);
var hasHit = Physics.Raycast(ray, out var hit, float.PositiveInfinity, 1 << meshManager.meshPrefab.gameObject.layer);
if (hasHit)
{
if(lastSelectedObject == null)
{
lastSelectedObject = Instantiate(placedPrefab, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)).GetComponent<PlacementObject>();
points.Add(lastSelectedObject.transform);
line.SetupLine(points);
}
else
{
if(lastSelectedObject.Selected)
{
lastSelectedObject.transform.position = hit.point;
lastSelectedObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
}
}
}
}
}
Best,

