[C2] Destroy object problem

Get help using Construct 2

Post » Wed Nov 09, 2011 6:31 pm

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?
B
6
G
2
Posts: 16
Reputation: 1,357

Post » Wed Nov 09, 2011 6:36 pm

can u post the capx?
B
15
S
1
G
2
Posts: 62
Reputation: 1,696

Post » Wed Nov 09, 2011 6:43 pm

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
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Wed Nov 09, 2011 7:02 pm

@ 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?'

Edit:
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?TheMightyAtom2011-11-09 20:07:21
B
6
G
2
Posts: 16
Reputation: 1,357

Post » Wed Nov 09, 2011 8:12 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Wed Nov 09, 2011 8:39 pm

@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.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Wed Nov 09, 2011 8:54 pm

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?TheMightyAtom2011-11-09 20:57:07
B
6
G
2
Posts: 16
Reputation: 1,357

Post » Thu Nov 10, 2011 4:30 am

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 :DAlexmosuTSP2011-11-10 04:31:46
B
9
S
2
G
4
Posts: 19
Reputation: 2,648

Post » Thu Nov 10, 2011 4:55 pm

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?
B
6
G
2
Posts: 16
Reputation: 1,357

Post » Thu Nov 10, 2011 11:00 pm

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
B
9
S
2
G
4
Posts: 19
Reputation: 2,648

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 30 guests