Triggering event based on Family Distances

Discussion and feedback on Construct 2

Post » Thu May 05, 2016 4:48 am

I've had several situations in C2 where I've wanted to trigger a function call once, and only once, when two objects in different families come within a given range of one another - similar to an 'on Collision' trigger, but I need it to happen before the objects actually collide.

I've dived into this problem a little bit more tonight, and at first I thought it was a bug, but now I think I may just be misunderstanding something about what's happening in the engine.

Here's a capx to demonstrate: ... eport.capx

In this scene, there are 2 families of squares, Blue and Red. The intended behavior is that whenever two squares in different families enter a radius of 200 px from one another, they should each fire off a single bullet of their color at the closest member of the other family.

This seems to work fine, except in the case where BOTH blue squares are within range of one or both Red squares - at that point, the event stops behaving as a 'trigger once while true' and starts to fire every tick.

Can anyone explain why this is happening? I can think of a couple of workarounds for this problem, but I'm more interested in understanding the underlying reason why this particular situation doesn't work.

And better yet - what *is* the simplest way to trigger an event once and only once when members of different families enter into a given range of one another? I'm looking for a solution where for at least one of the families, I won't know the exact number or type of the family members.

Thanks for any insight or help anybody can offer!
Posts: 4
Reputation: 1,110

Post » Thu May 05, 2016 6:20 am

I would probably put an instance variable on the family, and set it to the opposing family currently in range. If none are in range it's not set. If two try to set it, they both set it to the same number anyway.

Here is an old example I posted once using the turret behavior for range and detecting. It's like a zombie sim, they turn toward the last place the player was in range. Turret has several built in functions that may work here, but I just share if it should spark an epiphany. ... Range.capx
Last edited by Paradox on Wed Jun 08, 2016 2:43 pm, edited 1 time in total.
Posts: 902
Reputation: 40,398

Post » Thu May 05, 2016 10:44 am

I beleive this is the logic that you are looking for, staying on topic regarding the question.


Beyond your question, as Paradox states, a turret works fine, just have to cage the 'on shoot', or set the firerate so it shoots once in an hour.

A little bit further then the question. I suppose this is an embrional part of a much bigger game system. Maybe at one point you need to dedect obstacles between the families, or even members of the same familie are obstacles to each other. Then a turrent will not be the solution.

In that last case is you original plan (when implemented right) easyer to expand with new rules. Or you migh choose allready now for Lign Of Sight (with its specific problems and workarrounds)

Hope i helped some.
Posts: 2,493
Reputation: 20,950

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 19 guests