Retrieve contact point on collision with tilemap

Hello,
I’m making a little 2D game and i’m looking for contact point on tilemap.

First gameobjet :

  • CircleCollider2D → isTrigger = false
  • RigidBody2D → Dynamic with mass = 0

Second GameObject

  • Tilemap renderer
  • TilemapCollider2D → isTrigger = false
  • RiggidBody2D → Dynamic with mass = 0
  • Script for detecting collision
void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log("contact");
        if (collision.gameObject.tag == "IceAura")
        {
            Debug.Log("Contact with Spell");
            ContactPoint2D contact = collision.GetContact(0);
            Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
            Vector3 pos = contact.point;
            Debug.Log(pos);
        }
        else if (collision.gameObject.tag == "joueur")
        {
            tm.isTrigger = true;
        }
    }

My probleme is the OnCollisionEnter2D not calling when the two gameobjects (Spell of player and water) collided.
I tried all configurations (isTriger true/false, with Rigidbody or not etc.)
I can’t use OnTriggerEnter2D (this function is ok) because i want the exact collidePoint between the two objects.

Thanks for your help.

Stéphane

Could you share the settings for your GameObjects with screenshots of the Collider2Ds and other Physics2D Components for the Spell of player and water GameObjects?

1 Like

sure

@ChuanXin : below informations.

Ice is the moving gameobject.
Tilemap is fixed gameobject. The script that detects the collision is in Tilemap.

Sorry but i don’t found a solution to get properties with json.

Thanks for your help.




Just to check, in Ice_1 and Ice2.png, it seems that the Circle Collider 2D is disabled? The checkbox next to the name of the component is not checked. This means that there will be no collisions for this GameObject.

ChuanXin,

thanks for your help.

Circle collider 2D is enabled by Animator.
See video screen on link https://drive.google.com/file/d/1X16phyCXoEtOY4fLr73x9y2ln3NX6E-S/view?usp=sharing

Best regards,

0.08s

The alert in the RigidBody2D suggests that the enabled Circle Collider 2D is not in the simulation which could be causing the issue. I’ll ask about this!

6485058--728799--upload_2020-11-3_12-30-14.png

Totally correct yes. If you take it out of the simulation then it’s not going to be part of it so all attached colliders, joints, effectors and associated contacts/callbacks won’t happen. Doing this is the most efficient way of doing that but you can’t take it out of the simulation and somehow expect it to be in the simulation.

@ChuanXin @MelvMay

I change my parameters but i can’t do what i want.
Both objects have Colliders2D and RigidBody2D (maybe is not right ?)
Even by checking the box “simulated” i can’t find the point of collision

see video with both parameters objects.
https://drive.google.com/file/d/14e0tdEc-jlBH09UzfJk2BIRgF0j59Rgy/view?usp=sharing

Thanks for your help.

It looks like the Ice Aura Circle Collider 2D has “Is Trigger” set. That would correspond with the OnTriggerEnter2D method instead of the OnCollisionEnter2D. Could you check that if “Is Trigger” is unset, your code is called? Thanks!

Additional to what was said above, for your tilemap/composite you’ve got all the constraints set to stop it moving and you’ve set its mass to 0.0001. That’s what a Static body-type is for so change the body-type property to Static. It’s not clear why you’ve set all your other masses to be so very small too; 0.1 of a gram!

1 Like