Collision issue between FlxSprite and FlxTilemapExt

143 views
Skip to first unread message

Michael Zehnich

unread,
Nov 3, 2015, 6:07:21 PM11/3/15
to HaxeFlixel
Hi there! So I'm making a platformer where you can run and jump around a tilemap, and shoot bullets. I'm using FlxTilemapExt to get the sloped tiles. Also, I'm on the dev branch of Flixel.

I'm using FlxG.collide(this, map) in my bullets update function to check and see if the bullet has collided with the world. The issue I'm having is that this collide function returns true when not actually colliding with the sloped tiles, causing the bullets to collide with the tile when they're still a good 20+ pixels away from the tile (regular, non-sloped tiles work fine)

If I don't use this collision and just let the bullets fly and bounce off the environment (with both the bullets and map using default allowCollisions), they hit the slope perfectly and slide up and off them.

This is really best described with images, so here's some gifs:

http://imgur.com/Rx8oOax -- The bullets have no FlxG.collide function and simply slide off the slope at the points you would expect them to

http://imgur.com/RuaJ8Cv -- The bullets have a FlxG.collide with the map, with a callback function that zeroes out their velocity

I've looked over FlxTilemapExt.hx and can't find the problem in there (though I'm sure at least the part where the slopes seem to extend an extra tile's length to the north and west has to be in there?!). I also tried using FlxG.pixelPerfectOverlap in the callback function to ensure that it actually hits the slope's pixels but this function needs sprites, and I'm not sure how to get and pass the specific tile from the mapgroup...

Sorry for the super weird question/bug but any help would be appreciated, been stumped on this one for a while now!

MegaLeon

unread,
Nov 4, 2015, 5:33:40 AM11/4/15
to HaxeFlixel
I believe it's good practice to always collide the map with the object and not the opposite: FlxG.collide(_map, _object)

Adriano Lima

unread,
Nov 6, 2015, 8:05:54 AM11/6/15
to HaxeFlixel
Could you give some simple example code reproducing the problem?
I know how use the map but I never worked with bullets, maybe I can find a solution for you, and if needed update the dev.

Michael Zehnich

unread,
Nov 6, 2015, 2:43:10 PM11/6/15
to HaxeFlixel
Hey there, sure, I made a minimal project using all the relevant code to reproduce the bug, zip here:


This is on the dev version of flixel and flixel-addons.

Here's gists of the code:


The bug is basically, in the Bullet.hx update function, if the FlxG.collide function has a callback, it seems to act differently. If I just do FlxG.collide(bullet, map) then it works as expected: the bullets hit the slopes at the correct point and slide diagonally off of them. If you use FlxG.collide(bullet, map, hitwall) with the callback then this makes the bullets collide at a distance much further away. 

Thanks!!

Adriano Lima

unread,
Nov 9, 2015, 6:55:24 AM11/9/15
to HaxeFlixel
Hey Michael, 

The overlap check is based in the bounds of the objects, and uses Quads. I don't know a good way to override this. We have to find a hacky solution.

So your first try with another check inside the callback was a good start, but instead of `pixelPerfect` you could check `this.tounching > 0`

```
//inside the callback of the bullet
if (this.touching > 0)
{
velocity.x = 0;
velocity.y = 0;
}
```

The overlap is called when it get inside the bounds, but the touching is changed only when it touches.. This hacky solves for you?
Sorry if I'm late...

Michael Zehnich

unread,
Nov 9, 2015, 1:19:12 PM11/9/15
to HaxeFlixel
Ah wow I hadn't even thought to check the touching flags! It works perfectly! The early collision of the sloped tiles doesn't set any touching flags, so only making the bullet explode when it hits the wall when touching is > 0 works great! Thanks so much for your help!
Reply all
Reply to author
Forward
0 new messages