User Tag List

Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 27

Thread: Broad Phase Collision Detection

  1. #1
    Clicker Fusion 2.5 (Steam)

    Join Date
    Jul 2014
    Posts
    92
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Broad Phase Collision Detection

    Hi Everyone,

    I have a platformer that uses fastloops to do pixel perfect collision detection. It does this by using fastloops to move the object one pixel at a time then uses a detector to see if there is an overlap.

    I want to make it more efficient using a broadcheck before the steps and I thought I have two options, let me know which you think is better:

    1) Using conditions to see if all active object obstacles (using a qualifier) fall with in a box created from the player start position to their end position Then
    [i.e. obstacle Xpos>StartPlayerXPos, obstacle XPos < destinationXpos, same for Y etc...)
    Do a for each loop to count how many objects are in that position box
    If there is more than one then do the 1 step at a time collision detection in fastloop
    If there is none move the player to the destination

    2) I have a overlap detect object that is 1 pixel by 1 pixel. I move the detector and scale it to the size of this box (start X Y is player start XY end XY or the box is the destination XY)
    I check for overlap between the detector and the obstacle qualifer group
    If there is an overlap then do the fine per pixel stepping
    If there is none move the player to the destination

    Option 1 avoids using overlap and collision at all. Option 2 uses overlap once on a group of objects and requires scaling. Seems like option 2 is easier to implement however I wonder if option 1 is easier as it would just require scoping.

    Let me know what you think and if there is a better way.

  2. #2
    Clicker

    Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module

    Join Date
    Oct 2006
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about breaking it into 5 pixel chunks and then count backwards from the first positive collision? That's something like a 75% increase, assuming the added events for the countback.

  3. #3
    Clicker Fusion 2.5 (Steam)

    Join Date
    Jul 2014
    Posts
    92
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I tried to do the second method the problem I think I am running into is that the overlap collision mask isn't updating in the same frame. I think its keeping its original shape from the prior frame. This would make doing the broad phase collision impossible under method 2 I think.

    Your method might be an added bonus I can put on top as well for the move 5 check collision but it does add the risk that I teleport over something if it's small.

  4. #4
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have much experience with collision detection, and have tried many different methods.

    I wont mention all of them, as it can get a bit long and boring.
    Ill mention some of them and make it short though:
    ( forgive me if im missunderstanding your goal )

    STANDARD DETECTION
    I think the "Standard" or basic method to do movement detection is:
    - Object has X and Y speed
    - You move Object 1px at a time in X direction, and then in Y direction, untill it hitts an Obstacle

    ^
    - The problem i see with this is your running ALOT of loops, and if you have alot of Object/ Enemies, this can make things go slow ( depending of cource )
    - Its not quite accurate either if yur picky about it ( at hight speeds ), as real world objects move in a straight line and not in a zigzag pattern. For example, colliding with a block-corner makes Object "teleport" to either the top of the block, or the side of it. I repeat, if your picky about it
    - Object can also phase through Obstacles if it has enough speed

    STANDARD PUSHOUT
    - A better approach, imo, is to reverse the above: Object 'moves freely' but when overlapping Obstacle, it is 'pushed out' 1px at a time in the Xdir and then Ydir until it is 'no longer overlapping an Obstacle'

    ^
    - You use FAR LESS loops using this method, and only when nessesary
    - It is still moving in a zigzag pattern though, which can be logically inaccurate ( if your picky )

    EVENT PUSHOUT
    - ( I like this one the most ) Object moves freely untill colliding
    - By deploying a set of 4 - 5 Events ( no loops or anything ) you can push an Object out of any Obstacle by reverting to its previous X and/ or Y coordinates
    - Its movement pattern i 'similar' to Standard Detection, but does not use any loops

    ^
    - No loops are required, and its very easy to apply this to other objects and also 'multiple instance' withouth much hazzle ar any loops
    - As it reverts to its previous coordiantes, its not very good at 'getting right next to the Obstacle', but by trixing abit with its speed and such you can make it appoach the Obstacle with good sucess. In the case of a Player, if he wants to hug the wall he is going to by holding the arrow button for a millisecond or so
    - The movement pattern of this method is either Xdir, Ydir or both ( Straight line from A to B ), so it not a pure zigzag
    - Your using about 1 - 4 'collision checks' for each instance, but it resolves instantly and is no lag ( keep in mind there migh be a limit to nr of collision check per frame for Fusion )

    DIRECT DETECTION
    - This is maybe the most complicated, but possibly most efficient and accurate, but comes with some heavy luggage
    - If all your Obstacles are Active Objects...
    - You can use some calculations on a 'Collision Event', using the 'Objects and Obstacles coordiantes', to determine what side your supposed to end up on and directly 'teleport' next to the Obstacle without "approaching" it through use of loops or classic pushout methods

    - As far as i remeber you do have to use a loop to isolate the Obstacle your interacting with

    ^
    - Obstacles have to be Actives
    - It is like pushing Object out in either the X or Y direction, like a zigzag pattern
    - It can blow your mind
    - This will most probably not work on your first try
    - For 'moving obstacles' this is as accurate as you can get, as you are compairing directly to the coordinates and not he collision masks ( which has a lag )

    SUPPLEMENT: LINEAR MOVEMENT
    - You can supplement most of the above methods, and insead of working with the zigzag style approach, you can make Object move in incremets ( using some math ) in a line from A to B. ( like sliding along a line )

    ^
    - This is more "realistic" but not quite accurate as it moves in increments along the line not nessesarily representing 1px in both directions ( meaning you can very easily end up colliding a few fixels AWAY from the Obstacle ).
    - It uses loops, but not as many as it is moving in a 'straight' line
    - You can make it more accurate/ smooth by using 'floating point'/ decimal coordiantes and speeds or trxing with Objects speed etc, but mind that floating point values can bring its own minor problems as computers have problems with some decimal numbers witch can cause minor bugs/ issues ( if you are very very picky ). There are ways around that however, depending on how determined you are to use selected method.

    SUPPLEMET: LINE DETECTION
    - To prevent Object from "phasing" through smalal Obstacles, or if at very hight speeds, you can 'draw a line' from A to B, and if the line overlapps something you do deploy the Standard Detection, or maybe better with the Linear Movement.

    ^
    - This is a neat way of preventing phasing, and you can get away with using onlt 1 Line Object for all your moving Object with some tinkering.
    - I guess this can be used as a method by itself, or to supplement one of the above

    I think i mentioned all of them

  5. #5
    Clicker Fusion 2.5 (Steam)

    Join Date
    Jul 2014
    Posts
    92
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    King_Cool this is awesome!!! Christmas has come early . For your last line technique what are you using in fusion to draw the overlap line?

    After reading this I was wondering what should be the general order of events. For example;

    1) Update camera position
    2) move objects on screen position based on the camera
    3) move player
    4) check player collisions
    5) move enemies or obstacles
    6) check enemy or obstacles collisions
    7) show the screen

    Let me know what order your gameloop usually uses

  6. #6
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Drawing a line is relatviely simple.

    Use an Active Object with '1px of width' ( and its best to have at least 3px heigth ), leave the HotSpot at the center, and make sure to have the image in 'animaton dir right'.
    If you do this, its 'Scale' wil direct reperesnt its 'length' ( a Scale of 60 equalt a 60px line ).
    Now you can set the Angle of the Active to change the Lines direction.

    So, you can now set the lines Length and Direction.

    ...
    'Right' before moving your Player/ Object, store its previous coordinates in AltValues ( MemoryX_ MemorY_ for example )
    After the Object moves, create the Line at MemoryX/Y, and "draw" the Line from there to the current Player position ( by changing its Scale and Angle, the ADO Object can be usefull for this ).
    Now you check if the Line is Overlapping anything, and if it is you 'revert' players position and deploy an aproximation technique ( moving Player for its memory coords to the new ones while checking for Obstacle collisions ) of your choice ( Standard Detection or Linear Detection maybe ).

    The order in which you do things all depens, but here is 'basic' guideline i think is essential:

    - Store old coordinates
    - Move Object ( Gravity, Player Input etc )
    - Check for collisions/ Deploy a method

    Store an Objects previous Coordinates is IMENSLY helpfull and can help you get away with lots of things without deploying tedious methods.

    ...
    I attached an example of how to draw a Line.
    It uses math/ calculations instead of the ADO Object ( Advanced Direction Object ).
    The ADO is better in some situations, but youl just have to see how it goes, shouldt be that much a difference.
    Attached files Attached files

  7. #7
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    679
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    How does standard detection phase through objects? You move the object 1 pixel at a time, as you said, and check for ground each time. There's no way to phase through since you get stopped on a per pixel basis. I can have an object move at 500 pixels per second and it'll still stop against a 1 pixel thin backdrop correctly.

  8. #8
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    The 'blue line' is the 'percieved' movement and direction of the Object ( green ), while the 'red lines' are the path the Object 'actually' takes ( first executing all its X moves, then its Y moves ).
    The perception is that is phases right through the Obstacle, although logically ( behind the scenes ) there is nothing wrong.

    This could is more prominent at very hight speeds, and also if considdering collisions with fast bullets or small particles.

  9. #9
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    679
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Ah I was under the impression that you meant the object could pass through a backdrop when moving either only left or only down etc. Yeah, diagonally it would be a problem with very thin obstacles like that.

  10. #10
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to stress that although i mention this, its not like its a huge problem that many people nessesarily encounter or have an issue with.
    But its an observation of how things works technically.

    Although it 'may' look like a huge problem the way presented it in the image, you can probably deploy any method and never/ rarely feel the effects of this.
    Might be more prominent if Objects move at 'very' high speeds of cource, as mentioned.

Page 1 of 3 1 2 3 LastLast

Similar Threads

  1. Built in collision detection
    By Outcast in forum Multimedia Fusion 2 - Technical Support
    Replies: 33
    Last Post: 25th April 2013, 06:44 PM
  2. Possible bug in PMO collision detection
    By K1kk0z90 in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 4th August 2011, 01:56 PM
  3. détection collision
    By graboide in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 12th December 2010, 05:24 AM
  4. Bug with overlapping collision detection?
    By mobichan in forum SWF/Flash Export Module Version 2.0
    Replies: 5
    Last Post: 2nd April 2010, 11:16 PM
  5. Collision detection
    By Crash86 in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 1st April 2007, 04:50 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
  •