Hello,
I’ve been tinkering with AR Foundation and ARCore, but I’m new to the Android scene. I followed Dan Miller’s guide mentioned on this page: https://unity3d.com/how-to/create-AR-games-in-Unity-efficiently and main parts of my code are below. I had to change the code a little, since I’m using 2019.3.0a8. The main differences are that the raycasting isn’t on the ARSessionOrigin, I had to put the new ARRaycastManager component on the ARSessionOrigin.
I’ve been able to move the simple .apk and install it on a OnePlus 6T (heck of a time getting camera permissions), and now that I see the Plane starting to track on horizontal surfaces, it doesn’t really stay “in the world” - it’s always at the bottom of the vertical phone screen, and it stays at the bottom, relative to the phone. It will also start redrawing a new Plane on top of the existing Plane, still at the bottom of the screen. This just seems like a problem with the tools, not the simple code. I didn’t think it would be the .0a8 version, but maybe that’s it?
I’ve uploaded a screenshot showing the planes on the bottom of the phone screen, and here’s the code:
void Start() {
sessionOrigin = GetComponent<ARSessionOrigin>();
placeOnPlaneRaycastManager = GetComponent<ARRaycastManager>();
}
void Update() {
if (Input.touchCount > 0) {
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began) {
if (placeOnPlaneRaycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon)) {
Pose pose = hits[0].pose;
Instantiate(PrefabToPlace, pose.position, pose.rotation);
}
}
}
}