How do I use collision detection with a chain of sprites?

0 favourites
  • 14 posts
From the Asset Store
Detects any kind of ad blocker. Very easy implementation into already existing projects
  • I'm trying to make a VERY simple game, that let water flow through pipes (sprites) by using collision polygons and detection. You win the game by getting water to all the end points.

    I'm using a family to hold all my pipe sprites. The family has an instance variable boolean named "Flowing" to check if the sprite is flowing with water or not.

    Each sprite have a fixed position and turn 90 degrees when touched. If they are connected to the start sprite, they (should) play frame 1 (green) in the animation. If they are turned again and no longer connected, they (should) play frame 0 (red).

    [attachment=1:8f44t3d0][/attachment:8f44t3d0]

    But there is something wrong with my game logic thinking, I was thinking that as collision detection is happening all the time, it would set the boolean of the pipe sprites as soon as water gets to them, but that's not the case.. Whats wrong with my eventsheet?

    [attachment=2:8f44t3d0][/attachment:8f44t3d0]

    Am I not understanding how picking works? Should I be using functions or a kind of loop? I've read the manual on all those subjects, but I'm not getting it...

    I have looked at some examples of sprites colliding with sprites, but they don't seem to translate to my problem.

    ANY help will be greatly appreciated!

  • Let me ask you this.

    If the game was tile based, how would you check to see what tiles were next to each other without using collision detection?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Let me ask you this.

    If the game was tile based, how would you check to see what tiles were next to each other without using collision detection?

    I have absolutely no idea - An array? - I'm pretty new to this..

    Pick nearest?

  • An array would work.

    You can store the value "flowing" in the x, and y slot, and pick the instance by giving all the tiles instance variables that pick using the arrays x, and y.

    myinstancevariablex=array x

  • I have a basic understanding of what an array is, but have never really programmed anything before..

    So what I thought would be the simplest game ever, is now beginning to seem a little scary..

    Am I misreading your reply or are you telling me the only way to make my game is by changing it to a tilemap based game and using an array?

    Could it not be done with my simple collision check method? It might be resource heavy and not very elegant, but it seems to me it should be possible?

  • You could try is overlapping, and overlapping at offset, but on collision isn't ideal.

    Then again any game doing a bunch of collisions per tick isn't ideal either.

  • Overlapping gives the same result as collision - I can make the water flow from the first sprite to the second, but after that.. nothing. Im guessing it must be something to do with me not using a kind of loop?

  • Got a step further to the solution by finding "Falling Blocks" in the example folder.

    Im not really sure how the Pick instance with UID Function.Param(0) works, but the correct animations play depending on overlap. Now I need a way to check if they are connected all the way back to the start sprite.

    Does anyone have an idea where I should be looking?

    [attachment=1:1ppr9wxa][/attachment:1ppr9wxa]

  • For your own benefit you need to define what you want to happen in simple terms, but you need to give every little detail.

    For instance you might say you want it to check objects from the top down like gravity, or check each one to make sure they can flow first, or both as water flows down, but needs to have a path.

    You probably need a little more experience with how events work as well. The function for example is set to get called every tick, but events already run every tick.

    Likewise the "for each" is redundant with "is overlapping".

  • Got this working with simple trick

  • alextro Thank you! What a gift!

    So you add a layer with "invisible" sensor sprites that keep track of the connection to the start sprite. But as im trying to learn, would you (or anyone else) mind explaining what is... actually happening?

  • Oops.. you even don't need 'For each sensor', please disable it.

    When initial "Sprite" overlap with a "Tiles", it will trigger the corresponding Tiles to spawn a sensor that checks whether there is any overlapping Tiles within 4 directions at the edge (half width of Tiles). Each Tiles that overlapped by the sensor get the frame into a green color. Then instance variable "flowing" activated thus trigger chain reaction system that spawning another sensors for linked Tiles altogether. When the initial Sprite lost a connection to a Tiles, previous sensors destroyed completely and system reset.

    For spawn-wait-destroy part, is an experimental event I came up with when creating puzzle games. Usually puzzle-matching games rely on flood-fill mechanic. Just what newt said we can do it using an array to perform flood-fill. Alternatively we can also using direct overlapping test.

    Trust me I'm an expert over this subject

  • After looking up loopindex, and realizing that 51 was not an arbitrary number but half the tile/sprite size, I kinda worked it out.

    I was reading up on "Khan Academy's Intro to algorithms: Route Finding" (can't post links yet) and I guess that is an example of flood filling..

    And I DO trust you, even your gravatar looks like a puzzle of sorts

    Thanks again for helping me out and explaining whats now happening in my program

  • You got me then. Here is a good reading for another matching system:

    http://gamedevelopment.tutsplus.com/tut ... edev-11759

    By the way nice recommendation source you gave me. Thank you for pointing that, since I'm collecting pathfinding articles to build my own astar system.

    My sample for basic flood-fill (non diagonal picking):

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)