Refill of an air counter/bar when aquatic player surfaces
Zompar
Member, PRO Posts: 6
I am creating a game with the player (frog or submarine) under water. The player has an air counter that steadily counts down from lets say 20. my question/problem: how can i implement that the air counter counts up as long as the player hits the surface if the water?
I made an actor "sky", and once the player collides with the sky (so when has surfaced) the air counter counts up, but he does it just a single time. I need the programm to realise: as long as player touches sky the air counter fills up till the max is reached or till player dives again.
Thank you!
Comments
Probably easiest to have an "Every X Seconds" Timer. The change attribute on collision will only occur once, when it happens. Add the timer and change your air attribute every X seconds.
Age of Dominion RTS for iOS
Age of Dominion RTS for Android
Hi scott, thanks for your reply. Could you specify this a bit more, please? Right now i am using a timer that counts down the air counter. (every two seconds air count =air count-1. )
The counter shall count down while player is underwater and count up as long as he is on the surface of the water. Not sure how the counter can help me here.
You could make a boolean attribute 'surfaced' which turns true when actor collides with the sky, and otherwise turns false. When 'surfaced' is true every x seconds the air counter is increased and when 'surfaced' is false the counter is decreased.
The rule would look like this:
When actor overlaps or collides with actor [sky]
Timer every 0.5 seconds
Change Attribute self.airCounter to self.airCounter + 1
You can adjust the timer to any frequency you prefer.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
And just to add to tatiang's rule . . .
"as long as player touches sky the air counter fills up till the max is reached"
When actor overlaps or collides with actor [sky]
---When self.airCounter < max value
------Timer every 0.5 seconds
---------Change Attribute self.airCounter to self.airCounter + 1
Awesome, thank you for the feedback. I will try that out.
Yes, that's what I was getting at^^.
But (just thought of this) what triggers the "count down" of the attribute? If you just have it counting down at a regular interval, you may end up having it count up and down at the same time. Or possibly colliding with both (sky and water). Which is probably OK, you would just have to compensate for that.
For efficiency, you might look at putting your count DOWN behavior in the "otherwise" section of the rule that @Socks posted.
Meaning it would only count down when your actor is NOT colliding with the sky.
Age of Dominion RTS for iOS
Age of Dominion RTS for Android
Just to inform You, it worked fine just as you said. i also got the effect JScott mentioned (the counter counts dwon and up at the same time) and compensated for it by counting down very slow (while underwater) and refilling the air quickly (while surfaced). maybe not a perfect solution but it works fine enough. i did not need an boolean surfaced flag so far. thanks again!