I’ve currently got my game set up with edge colliders for obstacles in the level geometry. I then have my character object check where it’s about to move with Physics2D.OverlapCircle so that it won’t move into any collisions. However, it only recognizes the collision if I collide with the left-most line of the edge-collider, and I’m not sure what’s causing this.
I’m doing a platformer game prototype, by using Playmaker and TK2D.
TK2D uses EdgeColliders for its tile maps. I run a script to detect whether my character is touching the ground or not, and
changing his state on Playmaker accordingly. Obviously, it doesn’t work.
However, if my character falls on top of a platform with a BoxCollider attached to it, the landing event fires up.
I know there are alternatives, like using raycasting. But I think it’s unncecesary, this should be working, as that method is used in examples and in their live training sessions.
There’s really nothing wrong with using Raycasting though, it’s even what was used in the original Sonic games on the Genesis. It’s a pretty classic technique that doesn’t take much compute power at all, plus it allows for your character to begin moving to it’s grounded animations on the frame it’s actually about to hit, instead of hitting and then changing.
I have not seen a bug report for this but reading this it instantly triggered a thought of what it might be. A quick check this morning confirmed what the problem was. The bug was that the overlap checks for circle/area do not iterate the shape-index and only checks the first edge. This isn’t a problem for any other shape type but when the EdgeCollider2D was added, it was critical that all edges were checked until an overlap was found.
I am fixing this right now and it will be in a future release.
From the little i presume to have understood, using edge collider with circle overlap is quite more expensive than on other ‘linear’ colliders. Does this iteration on the edges may become heavy for a recurring check on multiple edges? like that for jumping on a broken ground may be? (I’m referring to last unity 2d tutorial and its ‘jumping technique’)
Does, for example, raycast could be a better solution?
Using an overlap check on an edge collider can be more expensive that a ray-cast, however, how much more expensive it is relates to your set-up. A simple check on your end with the profiler will tell you if it’s prohibitively expensive or if it’s a cost your project is willing to bear. In most cases I think you’ll no notice the difference.
No change in the news, it was fixed 2 weeks ago. Unfortunately, due to the way releases work, a fix one week won’t mean it’ll be in a public release the next.
I know this comes with the dangers of using 3rd party tools, hopefully it gets submitted soon. In the meantime I would really appreciate if you or anybody could point me to a work around? I know some people mentioned ray casting but I am unsure on how to make that work for this case specifically.