How do I, Only destroy a specific instance of an object?

0 favourites
  • 3 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • Hello!

    I am currently working on a side-scroller (platformer like) game, in which the Player has to eliminate the enemies, as usual. So, whenever a player destroys an Enemy of same type, they all get destroyed at the same, all of the instances of the Enemy get destroyed.

    How can I destroy only one, or specific instance which I attempted to destroy as a player.

    I highly assume its tied to my Eventsheet.

    I could share my file/eventsheet but that would be a bit long. Maybe there is a prioritisation, which I

    do not know when destroying instances.

    I found this on the forums, but I couldn ot understand it.

    construct.net/en/forum/construct-2/how-do-i-18/destroy-one-instance-object-125764

    In my game player can destroy an enemy if the enemys health (in instance variable) drops down to 0 or less. And when that event happens so, the "Death" animation of enemy plays and after the death anim finishes the EnemyBox(storing the Platform behaviour, which is juxtapposed to the anim) gets destroyed in final.

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do you mean it is destroying all enemybox and that's the issue? If that is separate to enemy so you're saying there are 2 objects then when enemy health drops below 0 if you then destroy an enemybox nothing is picked for enemybox so it will destroy all. If enemy and enemybox are in a container then it would pick correctly as they know about each other. If not this then please share a screenshot of the events related to the health and destroy logic.

  • So I ll try to explain the problem, btw, I've had contrived a way to fix the issue. I ll explain it later.

    I have a Bullet object which subtracts health from enemy bounding box in each collision.

    When enemy's health had gone below 0, I made the Enemy character's animation to play DeathAnimation. And then, promptly to delete the EnemyBoundingBox AFTER the DeathAnimation had Finished. The problem was that, every instance of Enemy was playing animation REGARDLESS OF THEIR INDIVIDUAL INSTANCE VARIABLE when one of the enemies "health" dropped below "0".

    For example: I have three enemies on screen, and when I inflict damage on any one of them, all of them Flash because "The EnemyBox is hit by a BulletObject and that triggers a Flash-in on on EnemyAnimation" so it does what it had been told correctly. This occasion had fooled me to think that all of the enemies were getting damaged when hit by a BulletObject, but it was a façade -- bullet collision only effected the appearance of all, and instance variable data of the instance which was actually hit by the Bullet.

    So, it took me to delete all of the EnemyAI events tied to the BulletCllision and Death triggers to find the issue.

    So, what I did to fix the issue was that, is by Spawning newly created sprite object of DeathAnimation of Enemy after EnemyBoundingBox had been Destroyed (or killed, virutally...)

    I can fairly guess that my explanation is specific to my project and can be hard to understand in general sense of the course of Collisions Logic.

    Had it had been that, if only the EnemyAnimation instance which is Set Positioned on top of the invisible BoundingBox which had been lowered its "health" below "0" to play the "DeathAnimation" -- I would not encounter this issue.

    However, the second option that I contrived it as a fix, is actually more logical somewhow. Yet, how could the Construct's event manager would understand how to play a specific animation when the BoundingBox's juxtapposed Animation instance had been triggered with an event -- for this case when:

    Condition = "

    EnemyBoundingBox>InstanceVaraible:"health"[lessOrEqual)then"0" " >> Action = " EnemyAnim > Set Animation... > "DeathAnim" OR, play an animation when hit by a Bullet. Since, there is no way to tell Construct that: "When BulletObject, on Collision with EnemyBoundingBox >> Set Animation, ONLY the AnimationsInstance which is the most closest to a certain Image Point (BoundingBOx centre most preferably) to play the animation -- doest not exist. And to achieve to only play animations on desired objects would be to stating to their instance variable states, RATHER than to what actually triggers the instance variable data to be altered. Ultimately, I was somehow mistaken to be expecting that when only one of the BoundingBox's "health" value had been decreased to 0, and only the EnemyAnimations instance which is tied to the BoundingBox would play the desired animations -- not knowing that it turns out to be playing the animation on every AnimationsInstances. Was puzzling... Oh, woe is me. Should always work with more than one enemy next time when testing for bugs etc. Thanks lionz for the support!

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