Is overlapping… Else on some instances ?

Get help using Construct 2

Post » Sun Aug 30, 2015 1:18 pm

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.

Image
(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 ?
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sun Aug 30, 2015 2:46 pm

Coin-coin le Canapin wrote: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.
B
96
S
33
G
20
Posts: 438
Reputation: 17,665

Post » Sun Aug 30, 2015 3:20 pm

That's what I finally did.
Thank you :)
B
12
S
7
G
7
Posts: 450
Reputation: 4,276


Return to How do I....?

Who is online

Users browsing this forum: farsen, lahbach, newt, TRMG and 22 guests