Forum rules - please read before posting.

Making my 2D Game display on an image marker in Augmented Reality

edited June 2022 in Technical Q&A

Hello AC Community,

I got a bit of a challenge for us all. I've made a simple Point and Click Game with AC and would display it on top a vertical poster with Augmented Reality.

I'm using Unity 2020.3.30f1 with AC 1.75.4. and Unitys AR Foundation to place the Game with AR.

As far as I can tell the main problem is the camera and the MainCamera (Script) since AR Foundation uses it's own AR camera.


I've tried to disable all _cameras and put the MainCamera (Script) on the AR Camera, but that didn't do the trick. (see image below)

Two background-images were rendered, which should not be the case.

Raycast seemed to be working, since the cursor changed position to where I was touching. But the player didn't move towards it.


I got the AR to work with simple cube. So I put the whole game in an empty parent object and hoped it would work the same, but of course it didn't.

Does anybody have any suggestions? Help would be much appreciated.

Comments

  • You don't need to disable your GameCameras - they are just used as position references for the MainCamera, and don't contribute to rendering. You'll also need to make sure there's only one AC MainCamera component in the scene.

    AC doesn't support AR officially, but here are two approaches you can try:

    1. Separate your AC MainCamera and AR Camera objects so that neither are attached / parented together, and attach AC's Basic Camera component to the AR Camera. You can then assign this as the scene's default camera / use the "Camera: Switch" Action to enable it, and the MainCamera will follow it.
    2. Parent your AR Camera to AC's MainCamera, and remove the Camera component on the AC MainCamera. AC will use the Camera on the AR Camera child object.
  • edited June 2022

    Hello @ChrisIceBox thanks for the reply. I had limited success with the second option. The game displays correctly and the AC cursor moves to my touch position. Menu is also shown and works.

    BUT the player does not move. Navigation works when I test the game in the game window, but not in AR. I suspect it has something to do with raycasting. With the AC Camera as a child object of the AR Camera - which camera is (should) cast the ray?

    I also now have two Cameras tagged as MainCamera, since the AR Camera does not work if not tagged. See screenshots below.

    Do you have any more suggestions? I fell like I'm close ;)

  • edited June 2022

    My second suggestion was to place the MainCamera component on the parent object - and the AR Camera on the child. From your screenshot, it looks like you've assigned things the other way around.

    Don't disable the Camera on the same object as the AC MainCamera component - remove it instead. If the AC MainCamera has no Camera on the same object, it'll search its children for one.

    When AC performs raycasting (for e.g. point-and-clicking), it'll do so from the AC MainCamera's Camera component - which I imagine should be the same one used by the AR Camera.

  • Ok, I've made the changes you proposed and the game displays correctly. It also starts up correctly. I put a few sounds in the onstart action list and it all works fine.

    BUT still no point and click movement! I tested the game outside of the AR Setup and it works. But as soon as I switch cameras it doesn't.

    I know there are a lot of potential problem-sources but at this point I don't even know where to start. I feel like I'm out of my depth. I am not a code-person ;) that's why I like AC so much.

    If anybody has any more suggestions I would be most happy.

  • But as soon as I switch cameras it doesn't.

    Through use of the "Scene: Switch" Action? I was under the impression this wouldn't be used in an AR game.

    Enable the AC Status window via the bottom of the Settings Manager - it should list the currently-active GameCamera if set. Does it list the expected info?

  • No, with "switch" I mean adding the Unity MARS Sessions and the AR Camera.

    I can't select the AR Camera as the Default Camera without the BasicCamera Script. That script however seems to collide with something inside the ARCamera with the result that AR doesn't work anymore.

    Can I leave the DefaultCamera blank or would that cause problems?

  • edited June 2022

    Great News everybody!

    I found a solution. In the end it was as simple as removing the MainCamera completely and adding the MainCamera Script and the AudioListener as Components to the ARCamera Unity MARS provides.

    The whole game is then put inside an empty game object and placed under the image marker. See image below.

    As soon as the ARCamera scans the marker the game is displayed and starts.

    Now that I figured out the basics hopefully the rest is charted territory.

    One other are of importance is the navigation. Since I build a 2D game in a 3D space a simple 2D Collider doesn't work. Unitys Navigation doesn't work either, because the baked NavMesh stays in world space and does not translate itself to the vertical poster.

    That leaves only the MeshCollider Option. I tested it with a simple plane and it worked. The next step is to recreate the walkable ares in Blender and swap out the meshes.

    I'm going to document the whole process as part of my MasterThesis and will post it in the forum as soon as I'm finished.

    But AC works with AR! Yeah!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.