How to Destroy Only One Spawned Actor?
JackSoft
Member Posts: 27
I'm brand new to GS and i've managed to create a small game. Its a simple top down game in which bombs spawn at the top of the game and fall. On collision with the hero I have an animation running, then the bomb is destroyed. The problem I have is that the animation is played on all bombs rather than only the one collided with. It sounds like I need something like self.Bomb but I'm lost. Thanks for any help. It's been great learning GS so far.
Best Answer
-
Socks London, UK.Posts: 12,822Try this:
Make a duplicate of your bomb actor - call it 'exploding bomb' (or something like that) - place the explosion animation in that actor . . . . . also remove the explosion animation (or rules that trigger the explosion animation) from the original bomb actor.
When the (original) bomb collides with the hero - have a rule that destroys that bomb actor and at the same time spawns the 'exploding bomb' actor.
Answers
This on the bomb should be treated independently:
When actor collides with hero
Run animation for bomb
Destroy actor (destroy self)
On the hero you'd have a collision rule similar to this:
When actor collides with bomb
Animate hero (if needed)
Deduct life or end game etc.
if collides with hero
->collision = true
if collision = true
->Animate
->Timer after .3 seconds
--> Destroy
-->Change Scene
Im not sure why the animation would not work with the first method.
Perhaps the animation didn't trigger because the destroy actor happened before the animation started/completed. Maybe a timer around the destroy actor would sort it i.e. after 0.5 seconds destroy actor, depending on how long your animation is.
when bomb collides with hero
->animate
->timer .5 sec
-->destroy
and... the animation is only showing the first frame like before. However, its only showing it on one bomb, the one on which the collision is happening.
I think you have set it up wrong ?
(file attached)
@Socks approach is something like this:
(Bomb Actor)
If actor collides with hero
Spawn explosion bomb actor
Destroy actor (destroy self)
(Explosion Actor)
Run animation
Destroy actor (destroy self)
If you find that the explosion actor destroys before the animation has finished then add a timer (After timer) around the destroy actor on the explosion bomb actor. If 0.5 is too quick then increase it to a second or two etc, however long your animation is.
I'm confused, I'm pretty sure you've just got it set up wrong, it's a really straightforward piece of logic.
Take a look at the example file in my post above - it works for me - 30 seconds work, very basic logic, not sure why it won't work for you ?