① Image Tracking
① Collider Trigger

The tutorial is for another tutorial <AR Portal>‘s final chapter, based on ARFoundation’s Image Tracking feature and Place on Plane.


① Image Tracking

Make sure you have installed ARFoundation and ARKit if you have a iOS device or ARCore if you are using an Andorid device, and created AR Session and AR Session Origin.

  1. AR Session Origin>Add Component>AR Tracked Image Manager;
  2. In Assets, create>XR>Reference Image Library;
  3. In Reference eImage Library, Add image and choose your target image, set a simple short name like “Card” but “TargetReferenceImage” (I have met some strange problem that Image Tracking not works with long name, and still don’t know the reason);
  4. Drag Reference Image Library into AR Session Origin>AR Tracked Image Manager>Serialized Library;
  5. Click ReferenceImageLibrary>Specify Size;
  6. Set the physical size (let the device know the ratio of the size between Digital Object and Real Objecy);
  1. Drag the prefab you wanna show when the target image is tracked into AR Session Origin>AR Tracked Image Manager>Tracked Image Prefab.

※Tips:

  1. Create a plane with a material using your target image as a reference to locate your model, set the plane as the physcial size(the default size of a plane is x=1 y=1 z=1, each 1 is 10 metre);
  2. Place your models on the ideal location to your target image (now it’s the plane you have just created);
  3. Create an empty GameObject and set the postion to 0,0,0;
  4. Drag your models as the child of the GameObject;
  5. Set the GameObject as the prefab you used as Tracked Image Prefab.

② Collider Trigger

This method can not only used for Image Tracking but any method that you can have something moved by your hand (AR Camera, Object Tracking or Gesture Tracking).

  1. Your Tracked Image Object, Add Component>Box Collider and adjust to a good form (fit your interaction’s needs);
  2. Click Box Collider>Is Trigger;
  1. Your digital object in the scene used for interacting, Add Component>Box Collider and adjust as well;
  2. The same object, Add Component>RigidBody;
  3. Unclick RigidBody “Use Gravity” and click “Is Kinematic”.
  1. Drag this script “ObjectDoorController.cs” into your digital object;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectDoorController : MonoBehaviour
{

    private void OnTriggerEnter(Collider other)
    {
        OpenClose(); //The function you wanna active when the collider is triggered;
    }

        public void OpenClose() //The function
    {
        Animator anim = this.GetComponentInChildren<Animator>();
        anim.SetTrigger("OpenClose");
    }

}

There are 3 ways of the collider interaction, I have linked on the titles:

  1. OnTriggerEnter
  2. OnTriggerStay
  3. OnTriggerExit

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

您正在使用您的 WordPress.com 账号评论。 登出 /  更改 )

Google photo

您正在使用您的 Google 账号评论。 登出 /  更改 )

Twitter picture

您正在使用您的 Twitter 账号评论。 登出 /  更改 )

Facebook photo

您正在使用您的 Facebook 账号评论。 登出 /  更改 )

Connecting to %s