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

Just started using Construct 2? Post your questions here

Post » Sat Mar 14, 2015 5:17 pm

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).

WaterFlow - Chrome.png


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?

WaterFlow - eventsheet.png


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!
You do not have the required permissions to view the files attached to this post.
B
9
S
1
Posts: 10
Reputation: 390

Post » Sat Mar 14, 2015 5:30 pm

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?
Image Image
B
164
S
49
G
111
Posts: 7,621
Reputation: 77,941

Post » Sat Mar 14, 2015 5:50 pm

newt wrote: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?
B
9
S
1
Posts: 10
Reputation: 390

Post » Sat Mar 14, 2015 6:25 pm

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
Image Image
B
164
S
49
G
111
Posts: 7,621
Reputation: 77,941

Post » Sat Mar 14, 2015 6:58 pm

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?
B
9
S
1
Posts: 10
Reputation: 390

Post » Sat Mar 14, 2015 7:10 pm

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.
Image Image
B
164
S
49
G
111
Posts: 7,621
Reputation: 77,941

Post » Sat Mar 14, 2015 7:22 pm

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?
B
9
S
1
Posts: 10
Reputation: 390

Post » Sat Mar 14, 2015 8:01 pm

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?

WaterFlow - eventsheet functions.png
You do not have the required permissions to view the files attached to this post.
B
9
S
1
Posts: 10
Reputation: 390

Post » Sat Mar 14, 2015 9:26 pm

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".
Image Image
B
164
S
49
G
111
Posts: 7,621
Reputation: 77,941

Post » Sat Mar 14, 2015 11:15 pm

Got this working with simple trick :mrgreen:
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
83
S
37
G
16
Posts: 636
Reputation: 16,815

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests