[C2] Destroy object problem

0 favourites
  • 10 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • I have a problem with my rockets in this little Space Shooter game I'm working on.

    Using Z and C you can fire rocket to the enemy. With each rocket, i also spawn a rocket exhaust sprite just to make it look cool. On collision with an enemy, the rocket is destroyed (as in removed). Any other rockets keep flying forward. I also tell it to destroy the rocket exhaust but instead of destroying the exhaust of the rocket that hit the enemy all the exhaust from all the rocket currently on the screen are destroyed as well. :o

    You can see it here: Space Shooter

    Wait for an enemy to appear and fire a bunch of rockets at it using Z and/or C. When one hits the enemy, you'll see that the rocket exhaust of all the other rockets are killed as well. I only want to kill the exhaust of the rocket that hit the enemy.

    How can i fix this?

  • can u post the capx?

  • use instance variables.

    On creation :set rocket variable shot to rocket.count, smoke set variable shot to rocket variable shot

    rocket on collision destroy rocket

    ->smoke variable shot= rocket variable shot : destroy smoke

  • 3DGS, my project is not of the single file type.

    I'm having trouble getting a clear picture of your post, Newt, sorry. 'smoke' is the exhaust?

    And what is 'shot'? Is that the instance variable name or is 'smoke' the variable name?

    'On creation' you mean 'System -> Create Object?'


    Tried really hard to understand your post, but i can't. Could you make your post again but make it more organized and clear this time?

  • Just using some pseudocode there, sorry.

    On create is when ever you create the objects rocket and exhaust, change an instance variable that you have made for each of them to correspond to each other.

    That way when a rocket is picked by the collision you can pick the exhaust that has the same value in its variable.

  • TheMightyAtom: you can make capx by "Saving as single file" within C2.

    A capx is basicly a zip file of a folder project, to make it easier to share it.

    Let us know if you still have troubles after Newt's explanation.

  • Ah that makes sense. But how do i tell it to destroy the corresponding exhaust? You can't give a parameter to a destroy action, right? Like: Destroy(RocketExhaust(Rocket.Index)) or whatever.

    I have this in my 'On C pressed' event:

    Rocket -> Set Shot Rocket.Count

    RocketExhaust -> Set Shot RocketExhaust.Count

    Where Shot is the instance var name for both the Rocket and RocketExhaust.

    Is that correct up to this point?

  • No you can't but you can put a condition in case of impact.

    Make an instannce variable to Exhaust, called "spawner".

    Make an instance variable in Rocket, called "EXA"

    Both with initial value -45678

    Add events :

    1 When c clicked- spawn Rocket

    2 every tick

    for each Rocket

    If Rocket"EXA" is not 1            

                              - Rocket spawn Exhaust

                              - set Rocket"EXA" to 1

                              - set Exhaust"spawner" to rocket.UID

    3 every tick

    For each rocket

    Exhaust "spawner" = rocket.UID

                                    -set Exhaust postion to rocket.x rocket.y (or whatever)

    4 For each rocket

    When rocket collisions with x

    Exhaust "spawner" = rocket.UID

                                     -Destroy Rocket

                                     -Destroy Exhaust

    May need a little tweaking.

    saludos :D

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That looks like that did it! I don't think it needs any tweaking though.

    Thanks so much.

    Also, why do i need to set the instance vars to -45678? Is that specific kind of value or something?

  • Just a random negative number so it never gets confused with 0 or positive UIDs that will spawn, maybe in this situation no more than 1 or 2 at a time, but who knows in other projects.

    saludos :D

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