Triggering event based on Family Distances

0 favourites
  • 3 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • 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:

    https://dl.dropboxusercontent.com/u/616 ... 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!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    https://dl.dropboxusercontent.com/u/854 ... Range.capx

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

    https://

    drive.google.com/open?id=0B1SSuCVV8v74dTJwQXRKNWxoX28

    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.

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