How to destroy multiple actors

Guys
lets take an example of space shooter game, a laser hits and falling object, I want to destroy both of them, then spawn a new object which shows collision and then disappear.

At the moment, I am destroying both the objects by collision rule and destroying actors by going into both the actors and writing that condition, is there any way I can write it at one place.

If (actor_laser collidedWith actor_falling_object)
{
destroy actor_laser;
destroy actor_falling_object;
spawn (blast);
}

at the moment this is how its working in terms of GameSalad
If (actor_laser collidedWith actor_falling_object)
{
destroy actor_laser;
}

If (actor_falling_objectcollidedWith actor_laser )
{
destroy actor_falling_object;
spawn (blast);
}

so doing it twice. any help will be appreciated.

Comments

  • bob loblawbob loblaw Member, PRO Posts: 793

    why do you want them in one place?

    you could do it a few ways, but the most efficient i think is leaving split. also if you are spawning an actor from one you are destroying, spawn before you destroy.

  • virk0009virk0009 Member Posts: 4

    Bob
    when a laser shot collide with a falling object, both needs to get destroyed, I feel it would be better if its at one place, otherwise one thing is happening at one place, second at other. its bit confusing. but thanks for your reply. i would like to know the other method also.

    thanks

  • bob loblawbob loblaw Member, PRO Posts: 793

    you could use unlocked actor instances, tables, or a tonne of new variables, all of which would be a lot less efficient methods than just having the rules you have in your prefab actors.

    OBJECT
    when object collides with laser > spawn explosion (and anything else you need to spawn or add to score) > destroy actor

    LASER
    when laser collides with object > destroy actor

    EXPLOSION
    animate > after x.y seconds (run to completion) destroy actor

    doing it that way you set up your logic once and it sits there clean and working consistently. if you’re using any numbers within your actor logic, i’d strongly suggest using private (self) attributes within the actor in case you need to change values (eg a timer value). it’s easier to find and change a value in a self attribute list when your actor has a long list of logic.

  • virk0009virk0009 Member Posts: 4

    Thanks Bob

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,170
    edited January 2020

    Yah. It's one of the quirks of the GameSalad programming model. For many beginners, keeping the concept of the logic close is easier to understand.

    As you grow, you hit the limits of that when you want to do things like control multiple actors from another actor.

    The only way I can think of doing it is to have each actor destroy itself by listening to an attribute.

    Then the logic "controller" can set that attribute whenever it wants things destroyed. It's still roundabout, but at least you can change the controller logic in one spot.

Sign In or Register to comment.