Is overlapping… Else on some instances ?

0 favourites
  • 3 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hi.

    I'm working on a minigolf game.

    When a ball enters a sand area (trigger once), its linear dampling decreases. When it leaves the sand area (also trigger once), it comes back to the normal value.

    (I replaced here the linear dampling events by writing "a" or "b" on a text element so I can precisely see if the events are run once or continuously)

    The sand area is made from a dozen of sand squares instances.

    If only one ball is in the sand area, "a" is written once. If two balls are inside the sand area, the code is run continuously despite the trigger once condition : it writes "a" continuously instead or once (total of twice, one of each ball and that's a turn based game).

    Same for the leaving event: it writes "b" once if only one ball is outside the sand area, and it keeps writing "b" if both balls are outside the sand area.

    What I want is for each ball, the code is run only once when it enters or leaves the sand area, regardless the number of balls present in the same area.

    I guess this is pretty simple but I'm stuck on this and it puzzles me. Any idea ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi...Any idea ?

    I would give the ball an instance variable called something like "InSand"

    then if it enters the sand area, and the InSand variable is false, set it to true. (and set linear damping accordingly)

    then when the ball leaves the sand area and InSand is true, then set it back to false.

    that way you don't need trigger once, and having multiple balls wont make a difference. Once the variable is set properly, the code wont run again.

  • That's what I finally did.

    Thank you

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