Closed D33pTh0ught closed 4 years ago
The behavior should be the same on all platforms.
ARFoundation reports the result of the native API call from ARCore (Android) or ARKit (iOS) and there are sometimes minor platform differences.
The placed object should face the camera...
The desired behavior sounds like you are describing a specific use case, and you can certainly do that if that is what your app requires. You can use the hit position and then compute the appropriate rotation yourself (e.g., Quaternion.LookRotation)
Maybe the issue lies with ARKit then. The behavior however IS NOT consistent on iOS devices. When running the Interaction scene of this sample repository on an iPhone the objects that are spawned at the pose of the raycast intersection sometimes face in the same direction the ray was shot (as in Android) but most of the time have no rotation.
The desired behavior sounds like you are describing a specific use case
I'm not trying to describe a specific use case, it was just my best guess at what the rotation of a raycast hit is supposed to be. Unfortunately neither ARKit, ARCore nor ARFoundation's API or documentation is very specific about that. In any case, whatever it is supposed to do, it does not seem to do it in a consistent way.
As a workaround one could use Quaternion.LookRotation(Vector3.Scale(Vector3.one - plane.normal, _arCamera.transform.forward), plane.normal)
. This produces the same result as hit.pose.rotation
on Android but on both platforms and consistently.
I believe the rotation on iOS may be related to the orientation of the plane, which may be why it feels arbitrary.
I'm not trying to describe a specific use case, it was just my best guess at what the rotation of a raycast hit is supposed to be
Okay perhaps I misunderstood. However, my point is that if you require a specific behavior for your app, you can achieve that effect without relying on the raycast hit point having a specific orientation relative to the camera.
I believe the rotation on iOS may be related to the orientation of the plane, which may be why it feels arbitrary.
This would not explain why sometimes the reported rotation behaves the same as on Android. But even if that was the case it would still be useless without documentation.
Okay perhaps I misunderstood. However, my point is that if you require a specific behavior for your app, you can achieve that effect without relying on the raycast hit point having a specific orientation relative to the camera.
Sure, and for anyone interested I included the workaround for how to do that. If the issue really stems from ARKit reporting inconsistent values, then it might be of use to file a bug report there. As it is, the returned rotation from ARFoundation is either broken or useless without proper documentation.
We will review our docs and see if it makes sense to make this disparity in behavior amongst platforms more clear. Thanks.
Description The rotation of ARRaycastHit pose is sometimes not correct on iOS. (no issue on Android)
To Reproduce Steps to reproduce the behavior:
Expected behavior The placed object should face the camera (since the ray is cast from that direction). The behavior should be the same on all platforms.
Actual behavior Sometimes the spawned objects do not face the camera, but instead are all oriented along the same direction in world space (independent of the direction the camera is facing when the object is spawned).
Smartphone: