1

I am building an augmented reality app using ar foundation. I need to detect a collision between two cubes. The cubes both have a box collider and a rigid body attached to them. When I run the scene in the editor everything works fine but when I build it for android and then test it won't detect any collisions. Could it be because when one of the cubes is spawned it is already touching the other one?

enter image description here

I'm pretty sure its an issue with Unity and not my code but here is some of it just in case. I have also posted on Unity Answers here

void OnCollisionEnter(Collision collision)
{

    Debug.Log(collision.gameobject.name);
    
    if (collision.gameObject.tag == col_tag)
    {
        if (collision.gameObject != first && first != null)
        {
            //stuff
        }
        else
        {
            point = collision.contacts[0].point;
            first = collision.gameObject;
        }
    }
}
Dadu Khan
  • 369
  • 2
  • 16

1 Answers1

1

try using void OnTriggerEnter. In the box collider activate IsTrigger and try to use this script:

void OnTriggerEnter (Collider collision)
{

    Debug.Log(collision.gameobject.name);
    
    if (collision.gameObject.tag == "col_tag")
    {
        if (collision.gameObject != first && first != null)
        {
            //stuff
        }
        else
        {
            point = collision.contacts[0].point;
            first = collision.gameObject;
        }
    }
}
Theraot
  • 31,890
  • 5
  • 57
  • 86
Poke Clash
  • 106
  • 1
  • 4
  • Thanks for the answer! Can two triggers trigger each other? I thought one of them had to not be a trigger? Also, I don't think colliders have contact points but maybe I could use a raycast. – Dadu Khan Nov 15 '20 at 00:46
  • Maybe it's a problem with 2020(because what isn't?), I'll switch to 2019 and see if it works. – Dadu Khan Nov 15 '20 at 00:48
  • I'm using 2020, and not face such an issue – Mohamed Awad Nov 17 '20 at 11:48