Different Behaviour in Android-Emulator and on Device

Hello.

In UNITY-2D I have a Player-Object, a Loot-Object and an Enemy-Object.

They all are on the same layer.

Player and Enemy “Order in Layer” is 2, Loot at 1.

Now I do

m_boxCollider.enabled = false; // Player’s Collider

RaycastHit2D hit = Physics2D.Raycast(m_player.transform.position,Vector2.zero, 0f);

if (hit.collider != null)
{ // … Handle Collision … (( }

Running the Code in UNITY works, if Player stands onto Loot, Collision will be detected.

Running the Code in the Bluestacks-Emulator works, if Player stands onto Loot, Collision will be detected.

Running the Code on my Android-Device works not, if Player stands onto Loot, Collision will not be detected.

Edit: Running under Windows 10 works, Collision will be detected.

Why, why and why?

I really don’t get it.

If wanted, I will upload my Code and or the .apk.

Please solve this mystery for me.

Thank you.

Well I don’t know if you have found any solution, because I have similar problem.
When people are using emulators to play and record a video, some colliders are working fine, like objects falling throw walls or the floor, but in the real devices is fine.

Hello,

thank you for your reply.

I learned that using Physics2D.Raycast is sometimes imprecise.

Objects positions may vary a little bit and Raycast wont work anymore.

Someone told me that objects position may vary a little bit due to different screenresolution and, more important, aspect-ratio.

Cant tell if this is true, but now I test by time the positions of the objects and correct them if needed.

In the case described above I switched to Physics2D.OverlapBoxAll:

 BoxCollider2D boxCollider = GetComponent<BoxCollider2D>(); // Player's Collider.
  // Retrieve all colliders we have intersected after velocity has been applied.
  Collider2D[] hits = Physics2D.OverlapBoxAll(transform.position, boxCollider.size, 0); 
  foreach (Collider2D hit in hits)
  {
            // Ignore our own collider:
            if (hit == boxCollider) continue;
            ColliderDistance2D colliderDistance = hit.Distance(boxCollider);
            if (colliderDistance.isOverlapped)
            {
                if (hit.tag == "loot") f_dotjewech(hit);
                if (hit.tag == "enemy")  f_gameOver();  
            }
  }