So, in my script I have this code:
if (gobject.IsTouching(tlc))
{
Debug.Log("istouch");
}
gobject is a rigidbody2D, and tlc is a tilemap collider. Plus, it doesn’t give any error. What am I doing wrong?
So, in my script I have this code:
if (gobject.IsTouching(tlc))
{
Debug.Log("istouch");
}
gobject is a rigidbody2D, and tlc is a tilemap collider. Plus, it doesn’t give any error. What am I doing wrong?
Does your rigidbody also have a collider? Only two colliders can “touch”, using the rigidbody function will check all colliders associated with the rigidbody.
IsTouching doesn’t perform any queries, it simply checks if there are any active contacts between the respective colliders. In your case it’s asking if there any contacts between any colliders attached to the “gobject” Rigidbody2D and the “tlc” TilemapCollider2D. If you’re not seeing “istouch” then (as stated above) you either don’t have a Collider2D attached to the “gobject” Rigidbody2D and/or they are simply not in contact with the TilemapCollider2D.
You can visually debug contacts two ways:
Go into Project Settings > 2D Physics > Gizmos > Show Contacts (shows contacts as small arrows)
Go to a Rigidbody2D/Collider2D in the inspector and open the “Info > Contacts” rollout. You’ll get a complete list of active contacts. You can pause the project and see these but they are updated continuously.
Note that if you’re using a CompositeCollider2D then there won’t be any contacts on the TilemapCollider2D as all physics shapes (and therefore contacts) will come from the composite collider so you need to check against that.