How do I destroy the correct overlapping objects(same types)

Get help using Construct 2

Post » Fri Jan 30, 2015 12:21 am

icicle fall.capx


I have icicles fall from the sky and land randomly on the floor. I want to have an event check if any of the shadows, spawned under the icicles before they fall (showing the player where to not stand), are overlapping, then destroy the shadows and corresponding icicles to those shadows.

Currently it will kill the correct shadows but the icicles will get destroyed, more than they are suppose to.

I tried only having the shadows overlapping as the only condition but still if any shadows are overlapping all the icicles get destroyed, not just the icicles that have shadows overlapping.

Here is my algorithm. What am I doing wrong?
iciclepoper.png


iciclepoper2.png


I think it doesn't get the icicle number right since they are all of the same object and have different id numbers.
I was hoping for it to check after each shadow spawned and then destroy the objects then before the next shadow spawned but i think it spawns all the shadows and objects then checks for overlap and cant figure out which icicle to kill....

Any Help will be greatly appreciated thank you. I am still very new to designing games and get lost easy.
You do not have the required permissions to view the files attached to this post.
Last edited by HadesDC on Fri Jan 30, 2015 12:22 pm, edited 1 time in total.
B
4
Posts: 17
Reputation: 234

Post » Fri Jan 30, 2015 5:01 am

without seeing your capx...

have you tried an event like:

system> pick overlapping point > object: icicle, x: icicleshadow.x, y: icicleshadow.y
B
7
S
1
G
1
Posts: 13
Reputation: 422

Post » Fri Jan 30, 2015 12:27 pm

Added an Simplified Example Capx. in the main post. Still cant figure it out :( searched the forums no idea how to fix it?

I have a feeling it does have something to do with picking the right ones but I always seem to get all the icicles or all the shadows never the right ones.

Tried something like:

Function "check icicle"
(and)pick icicleshadow where icicleshadow.uid>icicleshadow.uid
(and) icicleshadow is overlapping icicleshadow
------> Destroy icicleshadow

The idea being to call the function every time a new icicle is spawned, then check if any icicles were overlapping each other and compare all the uid's. If any were (since it was called every time one spawned) it would have to be the one with the highest uid. so pick that one and destroy it.

long shot and didn't work heh
B
4
Posts: 17
Reputation: 234

Post » Fri Jan 30, 2015 5:23 pm

@HadesDC Now that I see the capx I think I understand. I think I have some ideas to try.

Just so I am clear:

is Sprite 2 just the method you used to set the correct position of icicleshadow from icicle?
does Golem have a function in your game or is it just used to set the initial position of icicle?
B
7
S
1
G
1
Posts: 13
Reputation: 422

Post » Fri Jan 30, 2015 5:24 pm

What I did in one of my games was to check if they were overlapping, then pick a random instance and it worked. Not sure if it's the best way to do it though.
B
35
S
9
G
3
Posts: 493
Reputation: 4,092

Post » Fri Jan 30, 2015 7:05 pm

You can try this:
Image
Last edited by alextro on Thu Apr 06, 2017 2:56 pm, edited 1 time in total.
ImageImage
B
111
S
51
G
24
Posts: 787
Reputation: 23,394

Post » Fri Jan 30, 2015 9:19 pm

@HadesDC what @alextro suggests will work as long as you keep that event outside the function "Icicle Drop" because you are using a keystroke as a trigger. Moving the shadows is ideal to destroying them. It is a bit slow the more objects you have on the screen.

icicle fall.capx


Here is another similar option where I have added some ideas on how to better control your icicles including putting the icicle/shadow in a container and the hit icicle/cracks in a container, breaking up the icicle drop function into multiple parts and using a global variable to determine the amount of icicles, not using the golem/sprite 2 to create the icicles/shadows, and I changed some of the triggers so that the icicle fall/ destroy was more organic and you don't see the slow spawn of the icicle shadows when avoiding overlap. You may have some challenges with icicles colliding with the wrong shadows and you may get better performance if you try the move to plugin rather than the bullet movement and use the move to rather than collision. But that is speculative, and you should use your best judgement based on your game design.

icicle_fall_test.capx


You could also use a recursive function to create each shadow at a distance from the last created shadow (only slightly faster and the pattern would look Fibonacci and less awesome), use a randomized array that has dynamically generated on start of layout non-overlapping spawn points (faster but more complicated), or use set spawn points (fastest but least awesome visually).

Good Luck! I bet your finished product will be very cool.
You do not have the required permissions to view the files attached to this post.
B
7
S
1
G
1
Posts: 13
Reputation: 422

Post » Sat Jan 31, 2015 8:21 pm

Wow Thank you both so much this completely fixed my problem and I learned about containers which i have already used in another problem i was having with destroying the correct corresponding stink cloud when one of my skeletons was destroyed.

Have a good day!
B
4
Posts: 17
Reputation: 234


Return to How do I....?

Who is online

Users browsing this forum: NN81, Yahoo [Bot] and 55 guests