How to Destroy Only One Spawned Actor?

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

  • SocksSocks London, UK.Posts: 12,822
    edited September 2013 Accepted Answer
    Try 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

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited September 2013
    It's odd for all bombs to animate and destroy. Have you got the animate and collision rule on the bomb or hero?

    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.
  • JackSoftJackSoft Member Posts: 27
    Thanks for the reply. Ill try it. Now, to learn how to spawn actors in place.
  • JackSoftJackSoft Member Posts: 27
    Sorry @KevinCross, I missed your reply. Originally, I had the animation/destroy set the way you describe but the animation would not play this way. It did affect only the "self" actor, but only the first frame of the animation would show. So, I searched and found a solution on the forum which was to create a game attribute boolean "collision" and set it to true on collision with hero. The when collision is true, run animation, destroy bomb and end game. The bomb looks like this:

    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.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited September 2013
    I can see why the approach you've taken will trigger all bombs. @Socks method will definitely give you what you need.

    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.
  • JackSoftJackSoft Member Posts: 27
    Hmm... Ive tried the method @Socks described and it has the same result. I think your idea about destroy triggering before the animation completed might be right. Ill look at that. Thanks for the help.
  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2013
    Hmm... Ive tried the method @Socks described and it has the same result. I think your idea about destroy triggering before the animation completed might be right. Ill look at that. Thanks for the help.
    The animation is not in the actor being destroyed, it is in the actor being spawned, so there's no problem with the original actor being destroyed before the animation is complete.
  • JackSoftJackSoft Member Posts: 27
    @Socks - The destroy triggering before the animation was pertaining to my original method. The method you described had the same result(all bombs showing animation). Im not sure, but it seems like no matter what, due to the fact that all of the rules are on the bomb prototype, they will all explode(run the animation). With the destroy and spawn new method, I think that all bombs are destroyed and all spawn the animation. So, now im back to the basic:

    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.
  • SocksSocks London, UK.Member Posts: 12,822
    . . . it seems like no matter what, due to the fact that all of the rules are on the bomb prototype, they will all explode (run the animation).
    The rule for running the animation is in the spawned actor - not the original bomb - there is no animation to run in the original bombs . . . .

    I think you have set it up wrong ?





  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2013
    Here you go, a very basic sketch of the idea - I don't have an explosion animation so I just used a numbered sequence, but you should get the idea.

    (file attached)

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    You definitely need to remove the game.collision = rule from the bombs and the exploding bomb actors. You don't need to set a game.Attribute to flag if it's collided

    @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.
  • JackSoftJackSoft Member Posts: 27
    I set it up as you described, new actor with animation. On collision destroy original bomb then spawn the new actor with the animation. It works, the animation is spawned, but is spawned for every bomb. Thats why I went back to the original idea of just letting the collision trigger the animation, but only the first frame is playing.
  • SocksSocks London, UK.Member Posts: 12,822
    I set it up as you described, new actor with animation. On collision destroy original bomb then spawn the new actor with the animation. It works, the animation is spawned, but is spawned for every bomb.
    How can every bomb be spawning the animation as the rules says 'when this object collides with that object then do this' - the other actors are not colliding with anything ?

    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 ?
  • JackSoftJackSoft Member Posts: 27
    Thanks for all of the help and the file. I'm not sure what I was doing wrong but I have it working now with you method. This was first experience with the GS forum and community and you guys rock!
Sign In or Register to comment.