How do I break the chain?

Not favoritedFavorited Favorited 0 favourites
From the Asset Store
A heart-pounding album featuring 8 electrifying tracks designed to fuel epic battles and high-stakes confrontations.
  • I'm not sure I can answer your question. Your game is pretty complex, and while switching to hierarchies has probably made things a bit cleaner and more organized, it's still a complex system.

    All I can do is share how I would probably approach this task:

    1. Pick all moleks that are still in the hierarchy (i.e. children of Chemic). First, set attached = false for all of them.
    2. For each molek in the hierarchy that is directly overlapping (touching) Chemic: set attached = true.
    3. For each molek in the hierarchy with attached=false: check if it’s overlapping another molek with attached=true. If so, change its attached to true. (You might need to use a family: “Molek is overlapping MolekFamily.”)
    4. Repeat previous step until none such moleks left.
    5. Any remaining moleks in the hierarchy that still have attached=false at this point have broken off from the chain. Remove them from the hierarchy and launch them away.

    This helps. How would Step 3 look like?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You'll need to add Molek sprite to a family, and move instance variables from the sprite to the family level.

    Then you will be able to pick both in the same event, something like this:

    Chemic pick children Molek
    Chemic pick children MolekFamily
    
     Molek is attached
     MolekFamily is NOT attached
     Molek overlapping MolekFamily 
     ----> MolekFamily set attached to true
    
  • You'll need to add Molek sprite to a family, and move instance variables from the sprite to the family level.

    Then you will be able to pick both in the same event, something like this:

    > Chemic pick children Molek
    Chemic pick children MolekFamily
    
    Molek is attached
    MolekFamily is NOT attached
    Molek overlapping MolekFamily 
    ----> MolekFamily set attached to true
    

    This confuses me a little. Where would it go?

  • What do you mean? Where what would go?

  • What do you mean? Where what would go?

    I meant to say, where would the script go in terms of lines? Also, would I have to replace every instance of molek with the family in the script?

  • That's not a script, that's Construct code in pseudocode. You can re-create it with events on the event sheet.

    You will need to use a family to allow picking two instances of molek independently in the same event, and then to check if they overlap each other.

    This event won't work because the same instance of molek can't be attached and not attached at the same time:

    Molek is attached
    Molek is NOT attached
    Molek overlapping Molek

    That's why we use families:

    Molek is attached
    MolekFamily is NOT attached
    Molek overlapping MolekFamily
    
  • That's why we use families:

    > Molek is attached
    MolekFamily is NOT attached
    Molek overlapping MolekFamily
    

    I figured as much. Would I use MolekFamily instead of Molek for all the preceding code as well?

  • You don't have to use the family in all code. Think of it as an alias. It's useful when you need to pick two instances of the same object in one event - one by object's real name and another by its alias (family name).

    Otherwise you can use Molek or MolekFamily, it doesn't matter.

  • Just so I can figure out if I got the aforementioned code right:

    But I must be doing something wrong, because very little has changed.

  • That's only a small part of the code. Did you implement all other steps? It feels like you don't fully understand the idea.

    Here is a demo - click any molek sprite to destroy it and break apart the remaining chain.

    dropbox.com/scl/fi/11l3w99yrnteao5t1atqn/MolekDemo.c3p

  • That's only a small part of the code. Did you implement all other steps? It feels like you don't fully understand the idea.

    Here is a demo - click any molek sprite to destroy it and break apart the remaining chain.

    Very cool. I see what you mean now. But now it leads to another question: with everything implemented before (That is here: construct.net/en/forum/construct-3/how-do-i-8/attach-sprite-specific-way-183986), with everything formerly worked on there, how would I now implement the new into the old?

  • with everything formerly worked on there, how would I now implement the new into the old?

    It's your game and only you can answer this question. I mentioned before that your system of attaching sprites with dx/dy instance variables and a dictionary was overly complex and error-prone. I understand you based it on R0J0hound's advice - he's a brilliant programmer, but he works in Construct 2, where hierarchies don't exist. In Construct 3, the hierarchy feature would be a much simpler and more efficient solution for your task. That said, you don't necessarily have to switch to it.

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