- Home /
The question is answered, right answer was accepted
Tilemap Collider 2D
So i have my sprite with rigidbody, and a collider on it - it can use my "door" portal thing fine - it can interact with other rigidbodies - and using a boxcollider 2d this works - however im trying to use tilemap collider 2d as trigger for this script - however just writing "Collider2D Col" in the constructor, does not work ? Anyone have a solution? I basically just need to know what its called, because TilemapCollider2D is not its name, nor is TileMapCollider2D - this is the error it gives me
"nterScript.cs(14,27): error CS0246: The type or namespace name TilemapCollider2D' could not be found. Are you missing
UnityEngine.Tilemaps' using directive?"
Also yes, the script is ON the tilemap in question. Does anyone know the correct syntax? Or know how i can have it interact.
Here's the code
void OnTriggerEnter2D(TilemapCollider2D col) //<--- THIS is the issue.
// There exists no reference to tilemap collider 2d's collision.
// And if there does, then i need to know what it is? Cant find it.
{
if (col.GetComponent<Player>())
{
Debug.Log("TestTileWorking?");
}
}
Edit1: - like i said to the person below, i know how tilemaps work, this specific tilemap is a child of its parent tilemap, this tilemap has enabled "isTrigger" https://imgur.com/a/O0dHKds and only contains the relevant tiles to trigger the script above- the PROBLEM, is, that the reference INSIDE THE SCRIPT - is not "TilemapCollider2D" - so then what is it? Because it isnt "Collider2D" - when i add a box2d collider i can use the script normally- but i want to very specifically use several individual tiles as encounters.
Edit2: - Still no luck, tried composite collider, with no result. Surely there must be a reference ? Obviously you'd want specific tiles on your tilemaps to have an effect?
Answer by fr0stsp1k3 · Aug 31, 2018 at 09:57 AM
Figured it out - i hadnt checked that the tile itself had "none" instead of "sprite" collision, worked after that.
Answer by TachyonBlast · Aug 30, 2018 at 06:29 PM
I think you are trying to use Tilemap colliders in a way they are not meant to be used. The way I understand it, Tilemap colliders are used to automtically create the collisions of the tilemap it is added to (All of the tiles will be affected). What you may be looking for is the Edge Collider 2D, which can act as a trigger and a collider.
Another solution using Tilemap collider could could be to create a child tilemap and paint there the tiles that need to trigger the script. This way every time you add a tile to this tilemap, it will already have the collider/trigger.
Yes thats what i've already done. And i think you're wrong about that. https://imgur.com/a/O0dH$$anonymous$$ds I have a specific child tilemap which is the tiles which encounters can happen - this child encounter tilemap, are as you can see, set to be a trigger- the entire issue is that -I CAN NOT- reference it in said script. It just doesnt register, because the reference isnt "TilemapCollider2D"
Sorry, read the question wrong. According to the documentation https://docs.unity3d.com/$$anonymous$$anual/Collider2D.html Tilemap Collider is not a type of Collider 2D so i'm not sure how would you do that. $$anonymous$$aybe try to make the Tilemap Collider be used by a composite collider? That way you may be able to get the calls from the composite.
Just tried that, didnt work. Hmm.. When i use a normal box collider, or any custom gameobject with a box or circle collider it works fine. But i refuse to think the developers didnt think of this? I mean its such an obvious and important thing