User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: Question about how overlap checks works

  1. #1
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,237
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Question Question about how overlap checks works

    I have been wondering a bit about this for a while, considering collision and overlap checks are regarded as so performance heavy.
    Say I have 1000 blocks in my level and my player object. If I check for an overlap with the player and a block will it run a check through every single block, or will it just check once if the player is overlapping 1 block?

    Also is there a difference here if I use a qualifier? If I check if the player is overlapping a qualifier for the blocks will that only make it check once instead of every single block (if that was the case)?

  2. #2
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export Module
    Konidias's Avatar
    Join Date
    Aug 2009
    Posts
    1,546
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    MMF checks every object that you reference... So if you have 1000 blocks, it's checking 1000 blocks. Qualifiers are no different. It needs to check every single instance of the object because it's not isolating just one.

    When you do something like:

    ActiveA is overlapping ActiveB, there is no way MMF knows which specific Actives you are referring to, therefore it needs to check every ActiveA object and every ActiveB object to test for overlaps. A good example of this... say you want ActiveA to change animation when it overlaps ActiveB... If you have 5 instances of ActiveA and 5 instances of ActiveB, then MMF needs to check all 5 of each to see if there are overlaps. Not just if a single ActiveA is overlapping a single ActiveB.

    Say that you have 5 of each and 2 ActiveA objects are overlapping 2 ActiveB objects... the rest are just scattered and not overlapping. Well then MMF needs to set animations for the two ActiveA objects that overlap. If MMF stopped checking after the first true case, then only one ActiveA object would have its animation changed... The other one would not, and therefore it would be "broken".

  3. #3
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export Module
    Konidias's Avatar
    Join Date
    Aug 2009
    Posts
    1,546
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    This is why it's important to try to keep things limited to box collisions, since MMF needs to check the vertex locations for each collision shape. If you have a box collision (the simplest shape) then it has 4 points that need checked... If you have a complicated shape, then it could have dozens of points that need checked per object... Which can multiply the number of calculations per object greatly.

    By the way, this is basically how collision checks are performed with every engine... so it's definitely not a bottleneck with MMF or anything. It's a problem with all collision checking.

  4. #4
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,237
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Ah ok! But why is then using qualifiers regarded as faster if it still need to check every single instance of objects that share a qualifier?

    Also by your examples I was thinking if the check was a bit "smart" so for example if you want to check one player active object if it overallps another instance of an active object (like a enemy) and there are 100 enemies and the event is if player overalps enemey then destroy player I was thinking maybe if it detects and overlap with one of the first enemey it checks for it would not have to check the other 99 because the event is already true.

  5. #5
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export Module
    Konidias's Avatar
    Join Date
    Aug 2009
    Posts
    1,546
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Dunno who said using qualifiers is faster... it's basically the same thing (if not worse) because all qualifiers do is group objects together... So instead of looking at a single object and it's instances, it would look at all objects in the qualifier and all of their instances.

    There would need to be a separate overlap check for what you mentioned (stopping after an overlap is true) but yeah that would speed things up a bit, in certain circumstances (it doesn't help if the objects overlapping are the last ones being checked, since MMF then has checked all other objects anyway)

    But no there is currently no condition that does that. "if overlapping" is all or nothing. There are ways to reduce the amount of objects being checked for collision though. For instance, you could theoretically set up something where only objects in a certain radius of the player are checked for overlap. You'd do this by first isolating only the nearer objects and then running a ForEach loop on only those objects. Since ForEach can actually loop through only objects that meet certain conditions, then it only loops through those.

    I actually did something similar for a game I worked on that involved hundreds of falling blocks on screen. If a block had stopped moving, I stopped bothering to check it for collision because it was static at that point. I would then ForEach loop only through the moving blocks.

  6. #6
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,237
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Konidias View Post
    Dunno who said using qualifiers is faster... it's basically the same thing (if not worse) because all qualifiers do is group objects together... So instead of looking at a single object and it's instances, it would look at all objects in the qualifier and all of their instances.
    .
    Oh ok, I have heard it several times but I dont know why it would be faster.. Is it maybe because say you have 10 different enemies and you have to use 10 event lines to check collision with them, but you could just use 1 event line for a qualifier instead. Is that why it is faster?

  7. #7
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export Module
    Konidias's Avatar
    Join Date
    Aug 2009
    Posts
    1,546
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I don't think it would make much difference. Consider you have:

    10 instances of EnemyA with the "Enemy" qualifier
    10 instances of EnemyB with the "Enemy" qualifier

    You could do this:
    if EnemyA overlaps Player -> do actions
    if EnemyB overlaps Player -> do actions

    Or you could do this:
    if Enemy qualifier overlaps Player -> do actions

    All the qualifier does is reduce the amount of conditions in this case. Either way it's still checking all 20 instances of enemies.


    I think the best thing you can take away from all this is to try and isolate what you want to collision check before you do it. Even though isolating an object still means you have to loop through all of the objects, it's much faster to check positions of objects or flags then it is to check collisions.

    For example, lets say you have 50 instances of Enemy objects on your screen and 1 player object.

    You could do the normal overlap check like this:

    - if Enemy object overlaps Player object -> do actions

    Which has to check collisions for all 50 Enemy objects... or you could do this:

    - if distance between Enemy and Player is less than 100 -> ForEach loop through Enemy object

    - on ForEach for Enemy object
    + if Enemy object overlaps Player object -> do actions

    So the second method first isolates only the Enemy objects that are within 100 pixels distance from the Player object... and THEN it checks collisions for only those Enemy objects, instead of all 50.

    The reason why this is faster, even though there are more steps involved, is because checking the distance between an enemy and the player requires only 4 points of data. (the x,y positions of the enemy and player) while checking an overlap requires at minimum, 8 points of data (the 4 corner positions that make up a collision box for each object)

    This becomes even faster when you isolate enemies further... Like if you also check that an enemy is even capable of colliding with the player (if it's in a state that doesn't harm the player, or if it's currently animating a death sequence of something)

    You essentially want to isolate things down as much as possible before actually checking for collisions and overlaps. This becomes crucial in really heavy games with lots of objects on screen that need collision checks.

  8. #8
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,237
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Konidias View Post

    For example, lets say you have 50 instances of Enemy objects on your screen and 1 player object.

    You could do the normal overlap check like this:

    - if Enemy object overlaps Player object -> do actions

    Which has to check collisions for all 50 Enemy objects... or you could do this:

    - if distance between Enemy and Player is less than 100 -> ForEach loop through Enemy object

    - on ForEach for Enemy object
    + if Enemy object overlaps Player object -> do actions

    So the second method first isolates only the Enemy objects that are within 100 pixels distance from the Player object... and THEN it checks collisions for only those Enemy objects, instead of all 50.
    Thanks that make sense But I am not very familiar with the ForEach object. Is there a reason you use that object in the example above?

    Would it not be the same to have an event like

    - If distance between Enemy and Player is less than 100
    + Enemy object overlaps Player

    -> Do action

    Why do I need the ForEach for this? Does not the checking distance isolate the enemies close to the player so it only checks overlaps on them without using ForEach?

  9. #9
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,237
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Made an example using both foreach and without foreach to isolate. For me there are no difference
    Attached files Attached files

  10. #10
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export Module
    Konidias's Avatar
    Join Date
    Aug 2009
    Posts
    1,546
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Oh, well that isn't going to work that way... Notice your Global Value B isn't going up when you try the ForEach method.

    ForEach is isolating a specific object per loop... Meaning you can't do "objectA is overlapping objectA" since it's only looking at one of them. I hope that makes sense.

    Doing "objectA is overlapping objectA" is never going to work well, because it's going to have to check all objectA instances regardless.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. End of array condition checks first?
    By mobichan in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 4th November 2012, 12:01 AM
  2. Object overlap - Overlap area
    By Ls2 in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 12th May 2012, 10:06 PM
  3. Background collision vs. overlap question
    By Drcooper in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 9th August 2010, 10:47 PM
  4. Qualifier Overlap Question
    By HammerBro in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 23rd December 2008, 06:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •