Multiple Overlap Problem



  • I have a problem with multiple overlaps when the objects overlapping are on a quadrant border.

    I thought I fixed this by setting FlxG.worldDivisions = 1, which it did solve the issue under some circumstances. I found out about this in the discussion here.

    It was 'mostly' not noticeable with mob/player collisions even though it was causing double hurt(), but I have a toggle switch that it became a real problem, since it would turn on and off instantly due to the double overlap.

    I'm using FlxG.overlap(player, switches, toggleSwitch);

    This illustrates the problem. The 4 quadrants are gray, representing my world. The overlapping objects (player and switch) are represented by the colored squares. If the player and object are both on a quadrant border, I get multiple overlaps.

    Green: OK, only gets one overlap.
    Yellow: Gets 2 overlaps.
    Red: Gets 4 overlaps.

    Illustration

    Is there a setting I'm missing that will prevent this?

    Any help is appreciated! Thanks.



  • I'm bumping this old post with a test project to demonstrate the problem.

    Overlap Test

    Any help with this will be appreciated!



  • Confirmed. this bug should be on the critical bug list



  • Thanks for the confirmation @galoyo. :)



  • Hi, I'm not 100% sure what you whish to accomplish. But does substituting:

    FlxG.overlap(_player, _testObjectGroup, test);
    

    with something like this

    for (o in _testObjects) {
        if (_player.overlaps(o)) {
            test(_player, o);
        }
    }
    

    give you the desired result on your git repo?



  • Also:

    // FlxG.worldDivisions = 1;
    FlxG.worldBounds.set(0.0, 0.0);
    

    With the original code might perhaps give you the desired results. Personally i would recommend writing your own optimizations based on _player.overlaps(). instead of the world quads. Just check in advanced if any object is near enough to be eligible to be overlap. (simple x, y check).



  • @Username Thanks for that. It does work with this simple test project.

    I have many different sprites in several groups that need to interact with the player in this way, and other ways, other keys, etc. I'll need to add lots of code at this point and I'm not sure of any performance differences. At least I have an idea of a workaround.

    I'll try this solution with my toggle switches and see how it goes.

    Thanks again



  • Try this as a quick fix first:

    // FlxG.worldDivisions = 1;
    FlxG.worldBounds.set(0.0, 0.0);
    

    If it works and you don't have any real lag on your frames its probably okay to use if you dont wish to reconfigure your code. Else build an array and keep track of wat potentially might overlap you and then use the overlap from the _player on the list of potentials.

    Good luck!



  • @Username

    It works with the test project, but for my game I'll need to change/add some code. I'm using inWorldBounds() and kill() things when they're not. I can make my own function to check that, though.

    Thanks for giving me something to try.



  • @Username

    It looks like my only issue was the FlxG.inWorldBounds() check after setting FlxG.worldBounds.set() to 0. After making my own worldBounds var and inWorldBounds() function I was able to replace the FlxG.worldBounds/inWorldBounds() with my own. Now I don't have double overlaps. Thank you!

    So far, I haven't noticed any lag or frame rate drop.


Log in to reply