Destroy a specific attached item and not all on screen.

0 favourites
  • 5 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hi there,

    So I have a game where the enemies have a head attached to a body for the enemy. there are numerous enemies coming at the player. I'm using the pin function to attache the head to the body. Also I have an enemy that comes from the left and an enemy that comes from the right.

    So yea when i kill one of the enemy (body) it is destroyed which is right, but it destroys ALLLL of the heads for that enemy class on the screen. I don't want that to happen.. only destroy the head attached to the body that gets destroyed.

    I was trying a container, but i'm not 100% sure I did things correctly there and if that's the answer, I can dig deeper into that.

    Thanks,

    Caleb

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Container is the right way to do this. Add enemy and head into a container. When these two objects are in container, each pair of enemy+head instances will be logically linked together.

    If you place enemies on the layout manually in editor, put one enemy and one head first, then copy-paste them.

    If enemies are spawned during the game, you only need to create enemy object, head will be created automatically.

    Same with destroying - only destroy enemy object, its head will be destroyed automatically.

    If you want to do this without the container, you can use PinnedUID expression. Something like this:

    Enemy on destroyed:

    System-> pick by comparison EnemyHead where EnemyHead.PinnedUID=Enemy.UID -> EnemyHead Destroy

  • Thank you for the response!

    when i use a container i get some really weird behaviors.. i take the body and put a "head" in that body.. my understanding is that you'd put the head into the body container. this made things behave strange like heads no longer pinning and spawning in odd locations, no longer where they used too.

    or am i suppose to make a kind of blank/generic object that then has the body AND the head in that container to work right?

    Now your containerless suggestion is very interesting! i've never used that feature before and I would like to explore this approach to expand my understanding of C2/C3. I tried to follow it but i couldn't quite make the connection. it wants to compare two values. so is it an x values equals y value? how do i know those values. like how do i know the UID of the enemy head that is to be destroyed?

    in expression i put EnemyLeftHead.Pin.PinnedUID but i'm not sure what would go into "value" or how to put the "head to be destroyed" uid in there.

  • Containers are easy once you understand how they work. Objects in the container only exist together.

    If one object from the container is created, all other objects from the same container will be created automatically. So you spawn an enemy and don't need to create its head! (but you still need to position it correctly and then pin).

    If you create a head, another enemy will be created.

    You destroy an enemy, its head will be destroyed too.

    If you put enemies and their heads onto the layout in editor and do this out of order, then you may attach wrong heads to wrong bodies! That's probably why all those weird things you mentioned are happening.

    To your second question - PinnedUID is an expression of Pin behavior. When you pin head to the enemy, Head.Pin.PinnedUID contains UID (unique ID) of the enemy instance. (Sorry, I missed the .Pin bit in my previous comment)

    So with this expression you can find the enemy to which the head is pinned using "Enemy -> Pick by unique ID=Head.Pin.PinnedUID"

    or you can find the head using "System-> pick by comparison Head where Head.Pin.PinnedUID=Enemy.UID"

    The third and very popular option is to create an instance variable EnemyUID on the Head sprite. When you create a new Head, you will need to put Enemy's UID to this variable.

    Then you can pick the Head using "Head -> Compare Instance variable EnemyUID=Enemy.UID"

    Or you can pick the Enemy using "Enemy -> Pick by Unique ID = Head.EnemyUID"

    Endless possibilities!

  • Very cool! I'll try this. Sounds like I'll need to deconstruct how i did my spawning system but i follow what you're saying so it shouldn't be too hard

    Thanks!

    Caleb

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