How do I destroy an object without destroying every instance of it?

  • Hello, amateur here.

    I'm kind of a visual person so here's why I'm encountering:

    https://imgur.com/3KS9myh

    I used the "Ghost Shooter" events for the Monster object for the "upgrade orbs" yet they do not behave the same way as the template. They all disappear at once rather than only the orb that the ship touched. I have no idea where the problem lies and I'll gladly share my little project if need be.

    Any help is appreciated.

  • Construct by default picks all instances unless you narrow it down. The event ship on collision with object should pick only that instance, so what event did you use?

  • Hello Treshimek,

    what lions_ said should work!

    If you need further control, you can also give your orb object an instance variable / boolean and only turn this true if more complex events should reliably destroy only this orb.

    Example:

    Event 1

    IF

    on collision with "ship",

    time > 10 seconds,

    orb's health < 10

    THEN

    set orb's instance boolean (variable called "destroyable") to true

    Event 2

    IF orb destroyable = true

    THEN orb -> destroy

    Bottom line: Do as lions_ said and it should work perfectly for your example. But maybe for more complex ideas, you might want to give "instance variables" a closer look in the future to further influence when and which individual objects get picked.

    Hope this was somewhat helpful.

    Have a great day!

    Best,

    Chris

  • Thank you for the replies but all the instances are still being destroyed.

    To answer lions_'s reply, I am using the "On collision with..." event. How narrow do I have to make each event?

  • Heello Treshimek,

    you have to check your events than. Like said it should work as lions_ said.

    Here is an example file:

    drive.google.com/file/d/1Zq69THetcN6uXTa41837GbPji_-q4R8Z/view

    You gotta see how your "code" varies.

    You don't have a "for each loop" or a wrong "every tick event" or something like it in there I guess?

    Best,

    Chris

  • Right, I'm going to have to share my project. I honestly do not have any idea why my project's "destroy" event is not destroying only one instance.

    https://drive.google.com/file/d/1ewGrmqCEyMF7takn2dqWVJNgqjpDOIdX/view?usp=sharing

  • You got to make this gdrive link either public or accept my request ;)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You got to make this gdrive link either public or accept my request ;)

    Oh sorry!

  • You got to make this gdrive link either public or accept my request ;)

    It should be public to you now.

  • I figured out that the problem was because I wanted to use a two separate objects for the orbs: a hitbox and the actual sprite. I wanted the hitbox to be smaller than the visible sprite so that I could use the hitbox for movement while the sprite remains "stationary." That way, the art wouldn't rotate towards the player and it would not look weird.

    In this case, how do I link two objects together so that they are considered one entity? Or is there a way to allow movement without rotating the sprite?

  • You can use containers, or if you are Pinning the orb to the hitbox, use the "Destroy with pinned object" property.

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