I’m trying to create a AR Image tracking app and I ran into some issues, after narrowing it down I understood that the issue is due to the coordinates of the Tracked Image Prefab.
I put the current coordinates of the Tracked Image Prefab on a text on the screen. If the coordinates of the Prefab is always stuck at 0 0 0 all my issues will be solved immediately, but that’s not the case. The coordinates of the Prefab are different each time I run the app, not to mention it keeps changing as i move the Camera around. Is there a way to lock the (0,0,0) of the world to the IRL Image I have?
1 Like
I am trying to get the world coordinate of the prefab instantiated through ARTrackedImageManager but the result is always (0,0,0) can you share your peice of code ? i think i might help me with the problem…
private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
{
foreach (var trackedImage in eventArgs.added)
{
// Instantiate the prefab at the image's world position
GameObject instantiatedPrefab = Instantiate(prefabToInstantiate, trackedImage.transform.position, trackedImage.transform.rotation);
world = trackedImage.transform.position;
pos.text = "Position : " + world.ToString();
}
}
}
this code is generating (0,0,0)
Thank you for the reply,
That’s actually another thing that I’m curious at, I’m searching for the piece of code that actually instantiates the prefab, but I can’t seem to find it at all, and I don’t have any OnTrackedImagesChanged method at all.
I’m not an expert on the matter, so all I’ve done is add a script that keeps updating the text on screen with the coordinates of a game object. From that I got that the ARSessionOrigin is always at (0,0,0), ARSession and the Prefab moves around a lot based on the movement of the camera.
1 Like
The ARTrackedImageManager.cs
is the script that will instantiate the prefab. I don’t think we will be able to see the exact line.
The OnTrackedImagesChanged is most probably from this script arfoundation-samples/Assets/Scenes/ImageTracking/BasicImageTracking/TrackedImageInfoManager.cs at main · Unity-Technologies/arfoundation-samples · GitHub
If you want to get the Tracked image position as (0,0,0), is getting the prefab inside the Tracked image’s local position help with it? Or it need to be the Tracked image itself?
Generally you would use Transform.SetParent to set your content to be a child of the ARTrackedImage GameObject, then set your content’s local position and rotation to 0.
Thank you for your responses
What I’m trying to achieve is a simple AR Multiplayer game. The current setup is a plane with 2 spawn points on it. The issue is that the coordinates aren’t matching up on the 2 devices. On the host device, I’m getting the coordinates of the spawn points. When the client device connects it takes the coordinates from the host and uses them, but the plane is on very different coordinates than on the host device and thus the spawned objects are very far away. If I can get the coordinates of the plane to be set on 0,0,0 and stick that to the Image, it would work out. The other option being using coordinates relative to the tracked image prefab instead of world coordinates, which I have not yet figured out how to achieve that yet. Any further guidance regarding the matter is very much appreciated.
As you say, you could achieve this by using coordinates relative to the tracked image prefab. (Parent your content to the tracked image prefab, then send local transform data over the network.)
Alternatively you could consider Niantic ARDK which has a multiplayer solution built in.