How do I break the mass collision effect?

Get help using Construct 2

Post » Wed Feb 10, 2016 3:13 pm

I struggle with this for a while now.

I have several sprites in the "enemies" family. Enemies are walking from top of the screen to the bottom. At the bottom of the screen I have an invisible sprite which is simply a - let's call it - finishing line. So when the enemy touch the line, player loose and the score screen appears.

Now the problem is that if more than one enemy touch the line in the same time "On collision" events run multiple times.

I've tried even something like that

Code: Select all
On collision ->
     some actions
     disable "on collision" group


And it is fine for a while, because indeed it runs only once even when many enemies touch it, but then when I back to the play screen I have to enable this group again and then it instantly runs again. Like it have in the buffer.

Any ideas how to run On collision efect only once even when there are multiple enemies touching it?
Image
B
27
S
16
G
60
Posts: 893
Reputation: 34,400

Post » Wed Feb 10, 2016 3:19 pm

You could also use the Is Overlapping condition for this, since it is not an event it's not triggered as such, so there can't be any ''backlog'' that has to be processed, it only checks at that moment in time.

I use it to detect a sword hitting an enemy like this:
Image
B
5
Posts: 43
Reputation: 311

Post » Wed Feb 10, 2016 3:21 pm

On collision ->
Pick instance 0 ->
some actions
Last edited by blackhornet on Wed Feb 10, 2016 3:21 pm, edited 1 time in total.
ImageImageImage
B
71
S
21
G
204
Posts: 3,586
Reputation: 115,576

Post » Wed Feb 10, 2016 3:21 pm

You could make something like a trigger.

Create a local variable called "trigger" (needs to be static and needs to be reset to 0 at start of level)

For the collision event to run the trigger needs to be 0.
And if the collision event triggers set the trigger to 1.

So it should just run ones.
B
7
S
2
Posts: 56
Reputation: 583

Post » Wed Feb 10, 2016 3:31 pm

That's actually a fairly elegant solution, @dsminor. That way he won't need to disable collision on the object, but still retain his current workflow.

Image
B
5
Posts: 43
Reputation: 311

Post » Wed Feb 10, 2016 3:42 pm

I used this because construct has no real or function. (at least not as i understand)

So if you have an event with X subevents and you just want one of them to trigger and then skipping the other
ones thats what i did.

Or to make on/off switches with global variables (global variables cant be booleons so cant use toggle)
B
7
S
2
Posts: 56
Reputation: 583

Post » Wed Feb 10, 2016 3:44 pm

Thanks for the replies Guys.

Gumball wrote:You could also use the Is Overlapping condition (...)

Is Overlapping is not an observer condition, so with the number of my enemies that would be probably way to much CPU consuming...

blackhornet wrote:On collision ->
Pick instance 0 ->
some actions

If I'm not mistaken this will run multiple time anyway, just the effect of actions will go to the picked instance.

dsminor wrote:You could make something like a trigger.

Create a local variable called "trigger" (needs to be static and needs to be reset to 0 at start of level)

For the collision event to run the trigger needs to be 0.
And if the collision event triggers set the trigger to 1.

So it should just run ones.

Well yes I was thinking about adding a variable to check this, but somehow I don't find it the elegant solution, so I thought there must be some simplier way.

Anyway I will give a shot to all of the propositions. Thanks!
Image
B
27
S
16
G
60
Posts: 893
Reputation: 34,400

Post » Wed Feb 10, 2016 3:46 pm

BackendFreak wrote:Thanks for the replies Guys.

Gumball wrote:You could also use the Is Overlapping condition (...)

Is Overlapping is not an observer condition, so with the number of my enemies that would be probably way to much CPU consuming...
-SNIP-


Fair enough, I had not considered that to be honest. My current fidget projects are all PC based prototypes. :)
B
5
Posts: 43
Reputation: 311

Post » Wed Feb 10, 2016 3:48 pm

Ok then the hardcore way.

on collision--->destroy the finishing line!

finishing line on destroy---> get score and end level

It can only be destroyed ones so it can just trigger ones.

The levels ends anyway so you dont need it anymore. :)
B
7
S
2
Posts: 56
Reputation: 583

Post » Wed Feb 10, 2016 3:52 pm

dsminor wrote:Ok then the hardcore way.

on collision--->destroy the finishing line!

The levels ends anyway so you dont need it anymore. :)


It won't work. On collision condision trigger SOL is already in the memory so there is no second check if the line is there or not. That's why it's kinda tricky :)
Image
B
27
S
16
G
60
Posts: 893
Reputation: 34,400

Next

Return to How do I....?

Who is online

Users browsing this forum: AkbarAsgharMG, lwgames and 4 guests