Hello Guest

Author Topic: Tilemap colliders as triggers?  (Read 12521 times)

coopaloops

  • Newbie
  • *
  • Posts: 8
    • View Profile
Tilemap colliders as triggers?
« on: May 02, 2014, 06:11:09 am »
I'm using 2D Toolkit for a top down 2d game at the moment, and I've been trying to figure out how to handle collision detection in Unity. I want to find a solution to collisions that doesn't involve Unity's physics system. I don't want to use any Character Controller components or non-kinematic rigid bodies (all of my rigid bodies are currently being set to isKinematic for the purposes of firing triggers on other colliders that are set to be triggers). My current thinking is that I will just use the OnTriggerEnter method for handling all of my collision needs. Now, I absolutely love 2D Toolkit's tilemap functionality, and ESPECIALLY the ability to add colliders to each tile. It makes level editing so much easier. However, I don't think there is a way to set colliders on tiles to be triggers. I also don't think there is a way to tag the game objects that the colliders live on, which would also be super useful. If there is a way to do either of those things, I would love to hear about it...or if there is another recommended/better way to get a good collision system going in 2D Toolkit without using Unity's physics system, I would love to hear that as well. I'm mostly a beginner at this stuff, and am trying to avoid rolling my own collision detection system at all costs (I'd like to stay away from Raycasting if I can). To sum up - how can I make 2D Toolkit's tilemap collider system work for my needs? Thanks so much!

PS - as an aside, I would also love to hear any input on how to handle collisions without Unity's physics overhead in general...I've been googling all over the place and it can be hard to piece together information on this stuff. From what I can gather, people seem to generally suggest either using triggers for everything or doing some kind of crazy Raycasting system.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap colliders as triggers?
« Reply #1 on: May 02, 2014, 12:40:38 pm »
the tilemap colliders out of the box form a "skin" around level geometry. This obviously isn't particularly suited to trigger volumes. You have 2 options - use prefabs (http://2dtoolkit.com/docs/latest/tilemap/tutorial.html) or simply work stuff out yourself using the API. There is a function to get the tileid given a position - tilemap.GetTileIdAtPosition (http://2dtoolkit.com/docs/latest/html/classtk2d_tile_map.html). You can bypass triggers altogether, simply work out what sprite id you're on, build some means of mapping ID -> some data, and deal with it that way. If you want to skip the collision system entirely this would be the way to go. You'd have to deal with custom shapes yourself, but if your  game only used boxes this would be much much more efficient and also much easier to deal with.

coopaloops

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Tilemap colliders as triggers?
« Reply #2 on: May 07, 2014, 06:35:04 pm »
Thanks so much for the prompt reply! I managed to get collisions with walls working using raycasting, and it works flawlessly. Eventually I'll also want to have different tile types like pits, spikes, etc, and for those I'll just spawn prefabs that have trigger volumes on them. Thanks for making such a great tool and for continuing development on it.

coopaloops

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Tilemap colliders as triggers?
« Reply #3 on: May 07, 2014, 07:03:00 pm »
Oh, one other thing I should note is that in order to have the raycasts register hits, I'm having to use polygon colliders instead of box colliders on the tilemap. Apparently raycasts won't hit collision volumes unless the collision volume has a cap.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap colliders as triggers?
« Reply #4 on: May 07, 2014, 07:07:03 pm »
You can add caps to polygon colliders in the sprite collection editor - it should work with both types of colliders.

coopaloops

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Tilemap colliders as triggers?
« Reply #5 on: May 07, 2014, 11:11:42 pm »
Yeah that's what I did - added caps to the polygon colliders through the sprite collection editor. Front and back was the default setting I believe. Didn't see the option for caps with box colliders in the sprite collection editor though. Maybe I'm using an old version if that has been added in?

Also this might be a silly question, but would poly colliders be more expensive than box or mesh colliders (I think box colliders get converted to mesh colliders if they are adjacent) if the poly colliders are just boxes?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap colliders as triggers?
« Reply #6 on: May 08, 2014, 04:20:59 pm »
Box colliders are no different to poly colliders in a tilemap, they both get converted into polys. There is no option for box caps at the moment, using poly colliders will be no different.