HaxeFlixel / flixel-addons

Additional classes for HaxeFlixel
170 stars 136 forks source link

Collision displacement in TilemapExt #238

Open diegosolo opened 8 years ago

diegosolo commented 8 years ago

There's an (I think) old bug in TilemapExt that no one seems to have solved. It is very well described here https://groups.google.com/forum/#!topic/haxeflixel/hIyT0mRowCE. I've been checking TilemapExt.hx in an attemp to solve the problem and I couldn't find anything wrong, although I can't say I'm up to the task. In my case, the displacement isn't always the same, being sometimes half tile to the left, or one and a half tiles to the left, or other times one tile upwards. This varies according to the method use. So far, I've tried:

if (levelTilemap.overlapsWithCallback(player)) { ... if (FlxG.overlap(levelTilemap, player)) { ... FlxG.collide(levelTilemap, player, function(tilemap: FlxObject, player: FlxObject): Void { ... });

In my case, "player" is a group so the solution proposed in the link isn't possible. I just need to know if the player is colliding with any of the tiles, considering slopes...

adrianulima commented 8 years ago

Can you provide some code to I try to reproduce the problem?

In the callBack function instead of this.touching did you tried to iterate all members of the player group and check the touching flag of each one?

diegosolo commented 8 years ago

Very sorry for the delay. I though it would be a good idea to upgrade to HaxeFlixel 4.0 and I've been fixing errors that appeared after the upgrade. I was finally able to solve the problem with the hack posted in the link, checking, as you said, the touching flag on each member in the group.

Yet, the original problem persists. Let me prepare a minimal project tomorrow. It's been a long day :(

And thank you!

diegosolo commented 8 years ago

Here! With this project you can see exactly what the problem is. Morover, I thought this could have something to do with FlxTiled, but in this case I removed every non-essential aspect, including Tiled maps.

You'll see the player becoming red when FlxG.collide callback is called. With this test I could also find that the collide function works fine on its own, because FlxObject.separate has nothing to separate when the objects aren't actually touching. But the problem is clearly in the collision detection, that fires the callback when the player is inside a slope tile (even when not touching the slope) and, in this particular case, half tile before when the player approaches the surface from above, although I've see this happen from the left too.

TilemapExtTest.zip