Collision switch on/off rules. fixed...

ohtukrwohtukrw Sir dogeMember Posts: 106
edited July 2016 in Working with GS (PC)

My spawner spawns bird actor. I have set up game.lives attribute to keep track of hero ''lives''.

Bird rules:
1) When actor overlaps/collides with hero
change game.lives to game.lives-1

I set up a boolean attribute (killonce) on the bird, which is always true, for it to collide only once, then die.
2) If self.killonce is true
collide with hero
3) if bird collides with hero
change self.killonce to false

which should switch off the collision when it is hit once. So the lives won't continue to drop down.
But before bird falls off it may touch the hero couple more times resulting in multiple loss of lives.

Is the logic flawed? :neutral:

Comments

  • SocksSocks London, UK.Member Posts: 12,822

    @ohtukrw said:
    Is the logic flawed? :neutral:

    Yes, as long as you have rule 1 active then every time the bird overlaps or collides with the hero then game.live will go down by 1.

  • ohtukrwohtukrw Sir doge Member Posts: 106

    @Socks said:

    @ohtukrw said:
    Is the logic flawed? :neutral:

    Yes, as long as you have rule 1 active then every time the bird overlaps or collides with the hero then game.live will go down by 1.

    But 2 and 3rd rule should switch off the collision when it collides once? How can I fix this?

  • SocksSocks London, UK.Member Posts: 12,822

    @ohtukrw said:
    But 2 and 3rd rule should switch off the collision when it collides once? How can I fix this?

    Rules 2 and 3 have no effect on rule 1. Even though your collision behaviour (a behaviour that instructs the actor to bounce off another actor) is 'switched off' - the condition in rule one (when actor overlaps/collides) will still be met if the two actors collide, they just won't bounce off each other.

  • ohtukrwohtukrw Sir doge Member Posts: 106
    edited July 2016

    @Socks said:

    @ohtukrw said:
    But 2 and 3rd rule should switch off the collision when it collides once? How can I fix this?

    Rules 2 and 3 have no effect on rule 1. Even though your collision behaviour (a behaviour that instructs the actor to bounce off another actor) is 'switched off' - the condition in rule one (when actor overlaps/collides) will still be met if the two actors collide, they just won't bounce off each other.

    Added if self.killonce is true to rule 1.

  • ohtukrwohtukrw Sir doge Member Posts: 106

    @Socks said:

    @ohtukrw said:
    But 2 and 3rd rule should switch off the collision when it collides once? How can I fix this?

    Rules 2 and 3 have no effect on rule 1. Even though your collision behaviour (a behaviour that instructs the actor to bounce off another actor) is 'switched off' - the condition in rule one (when actor overlaps/collides) will still be met if the two actors collide, they just won't bounce off each other.

    Actually after adding that rule when birds got hit once, they stopped taking away lives, however this somehow disabled the boolean (killonce) to false for some other birds who never even got hit, I don't understand why.

    Current rules for birds:
    1) When (all)
    actor overlaps/collides with hero

    self.killonce = true

    change game.lives to game.lives-1

    2) if bird collides with hero

    change self.killonce to false

    :(

  • SocksSocks London, UK.Member Posts: 12,822

    @ohtukrw said:
    Actually after adding that rule when birds got hit once, they stopped taking away lives, however this somehow disabled the boolean (killonce) to false for some other birds who never even got hit, I don't understand why.

    Post a screenshot of your rules, that'll make it much easier to spot any errors.

  • ohtukrwohtukrw Sir doge Member Posts: 106

    @Socks said:

    @ohtukrw said:
    Actually after adding that rule when birds got hit once, they stopped taking away lives, however this somehow disabled the boolean (killonce) to false for some other birds who never even got hit, I don't understand why.

    Post a screenshot of your rules, that'll make it much easier to spot any errors.

    Socks thank you for prompt responses. I spotted the mistake only when writing it down.
    I am so stupid. Making hundreds of conflicting rules when it is only:
    boolean always true on the actor

    when (all)
    boolean =true
    collides with hero
    change
    boolean to false
    game.lives to -1

    new bird respawns, boolean is true again... :neutral:

Sign In or Register to comment.