Zhuokai Zhao
Zhuokai Zhao

Reputation: 51

Collision detection in ARToolkit for Unity

The background information of my program is that there are two markers tracked by ARToolkit camera. Each detected marker has a 3D object superimposed on it (one is a cube and the other is a sphere).

I've been trying to let the cube and sphere detect the collision between them, and become transparent when collision happens. However, I could not get the collision detection part right.

My approach is simple turning on the is Trigger option of the cube, and adding a script with following code to the sphere object.

private void OnTriggerEnter(Collider other)
{

    if (other.gameObject.CompareTag("Marker1_Object"))
    {
        print("Collision Detected!\n");
        other.gameObject.SetActive(false);
    }
}

where Marker1_Object is tag of the cube. I am using SetActive(false) just for testing.

Thank you in advance for any help!!

Upvotes: 0

Views: 186

Answers (1)

Zhuokai Zhao
Zhuokai Zhao

Reputation: 51

OK I have solved the problem. It turns out that you have to add Rigidbody component to either cube or sphere to get the physical engine run. Then the posted code can detect the collision.

Upvotes: 0

Related Questions