I’m making a simple AR app and I have 8 image targets with one child object for each of them that gets displayed when they image target is being tracked by the camera. I can only track one image target at a time. I’m also using LeanTouch to rotate and pinch scale the objects. Now, I have two questions:
-
How can I reset each object to their initial state when their respective image target is not being tracked?
-
How can I manipulate each object independently of each other? As of now whenever I rotate one object, then scan a different image target it will display its assigned object with the same orientation as the first one I rotated.
Example:
enter image description hereenter image description here
I tried using this script:
using UnityEngine;
using Vuforia;
public class ResetPositionOnTrackingLost : MonoBehaviour
{
private ObserverBehaviour observerBehaviour;
private Vector3 initialPosition;
private Quaternion initialRotation;
private Vector3 initialScale;
void Start()
{
observerBehaviour = GetComponent<ObserverBehaviour>();
if (observerBehaviour)
{
observerBehaviour.OnTargetStatusChanged += OnTargetStatusChanged;
}
// Store the initial position, rotation, and scale of the object
initialPosition = transform.localPosition;
initialRotation = transform.localRotation;
initialScale = transform.localScale;
}
private void OnDestroy()
{
if (observerBehaviour)
{
observerBehaviour.OnTargetStatusChanged -= OnTargetStatusChanged;
}
}
private void OnTargetStatusChanged(ObserverBehaviour behaviour, TargetStatus status)
{
if (status.Status == Status.NO_POSE)
{
// Target lost, reset position, rotation, and scale
ResetTransform();
}
}
public void ResetTransform()
{
transform.localPosition = initialPosition;
transform.localRotation = initialRotation;
transform.localScale = initialScale;
}
}
But it did not reset the models to their initial state once I removed the image target out of the camera’s line of sight then put it back again in front of the camera.