unity-game-enginearcore8thwall-xr

How to know object position in AR space? (inconsisten behavior between desktop and mobile)


I'm trying to move an element to another position in Unity using 8th Wall (new position selected by user on click) but this element is not going in the right direction. Everything work fine on desktop, but once I'm on AR mode the behavior is inconsistent. Is there a way to know elements positions in AR mode?

The code used in the Update() loop: my3DObject.transform.position = Vector3.Lerp(originalLocation.position, elementSelectedByUser.position, fractionOfJourney);


Solution

  • First, you shouldn't use Lerp for this, but SmoothDamp. Lerp is inconsistent depending on framerate, and will never actually reach the target used like this.

    Second, since both of the items you're trying to move are children of a single parent and move relatively to each other, using position might have unintended consequences. For example the interpolation here happens in world coordinates, which means that the original location could be far away from the parent if the camera moves. Using exclusively local coordinates would probably solve this.