Happen Only Once

0 favourites
  • 11 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • When my player has collision with a mushroom, the mushroom does a little dance and a sound plays then she gets health points.

    The problem is, if she stands still while touching the mushroom or moves back & forth over it, the events (sound & health points additions) happen over and over again until the animation finishes and the mushroom finally disappears.

    How can I make everything only happen once upon collision? It seems if I start with "trigger once while true", the "on collision" event is not available. If I start with "on collision", I am unable to add the "once while true" event on. It doesn't show as an available option.

    So how can I limit this event so that the actions only happen once per collision?

    <img src="http://www.eliyahna.com/temp/capture13.jpg" border="0" />

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • In your actions you could Disable collision for the mushroom

  • Disabling collisions on the mushroom disables everything resulting in no animation, no health points and well... no collision event.

    What did you mean? On the collision event these actions should occur once each. Not zero times each.

  • Create an instance variable in the mushroom object, and set it's default to 0. In the Collision check, first this set the variable to 1. Your condition should be on collision with mushroom and mushroom.variable = 0.

  • It seems if I start with "trigger once while true", the "on collision" event is not available. If I start with "on collision", I am unable to add the "once while true" event on. It doesn't show as an available option."Trigger once while true" always has to be the last condition in the list. The reason for not being an available option is that "on collision" already is a trigger that only executes once while true (this is indicated with the little green arrow). In your setup you have a wait action set to 3 seconds. Since the mushroom is therefore destroyed after 3 seconds have passed, the player has a lot of time to collide again with mushroom.

    Solution:

    Split your event. Mark a mushroom in the collision event (e.g. with an instance variable). Nothing else. Another event selects the marked mushrooms, but only if a second instance variable is of the right value (e.g. vanishing = FALSE) and does all the actions like sound playing etc., and finally sets the second IV to another value (e.g. vanishing = TRUE)

    EDIT: wizaerd, I apologize for being sooooo damn slow <img src="smileys/smiley36.gif" border="0" align="middle" />

  • Thank you both. wizaerd - I tried your way first. Works brilliantly.

  • Of Course the above practice probably the best but a simple solution without variables would be to add an other condition below the "is visible".

    That is the "animation is playing", write "Health Up" and invert it. So in essence you will have the following conditions:

    ->Player on collision with Mushroom

    Mushroom is visible

    X Is animation "Health Up" playing

    and then your actions...

    Provided that the animation "Health Up" doesn't end before the wait 3 seconds action that tulamide mention.

    Just to be sure you could create an other event that triggers the "destroy" action upon the animation "Health Up" completion.

    ->On animation "Health Up" finished ---> Mushroom Destroy

  • eli0s, unfortunately, the "health up" animation is interruptible (in case you have to defend yourself during) so it wouldn't work well.

    Oh here's the new working code. "Col" is the instance variable boolean on the mushroom:

    <img src="http://www.eliyahna.com/temp/capture14.jpg" border="0" />

  • Well, I am glad you worked your way with the optimal solution anyway! <img src="smileys/smiley2.gif" border="0" align="middle" />

  • Eliyahna - I'm glad that worked for you. I don't know if it's the proper way or not, but I started doing it this way a while ago and it works well enough for me. And you know what they say, whatever works...   <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Yes it does!! I think a few of these options would work well but wizaerd that's nice & simple. Thanks again for sharing!! :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)