The document describes fixes made to prevent players from endlessly throwing rocks by holding down the "K" button in a game. Originally, a timer was used to reset attributes after 0.3 seconds that controlled whether a rock could be thrown and the throwing animation. To instead require the player to release and press the button again, the timer was removed and a rule was added to reset the throw attribute when K is released. However, this stopped the animation from completing. So the rules were separated, with a new timer added to just reset the animation attribute, allowing it to finish while keeping the throw attribute reset until K is pressed again.
Fixing Rock Throw Mechanic to Require Key Release in Game
1. Fixing
the Rock
Throw
We wanted the player to not be able to old
down the K button and endlessly throw rocks,
so they have to press the button again for
another rock to be spawned.
We already had an attribute; 'Rock Thrown'
that was created to delay a second rock
being thrown. What Aaron had previously
set up was some logic that stated the rock
could only be thrown if 'Rock Thrown' = 0.
There is also a second attribute named
‘Throwing Rock’, that controls the
animation. If it’s true the throwing
animation plays, and if false it stops.
When K is pressed and the rock is spawned
Rock Throw changes to 1 and Throwing
Rock to true, meaning the rock can't be
thrown again and the animation plays. A
timer then switches the attributes back to 0
and false after 0.3 seconds, so you can throw
again, but 0.03 seconds after you first
threw.
What we wanted was for the player to have to
release the key ad press it again in order to be able
to fire again. I remembered that when setting up a
rule and the conditions, there was an option to make
the condition that a key was up, rather then down.
So first I turned that timer logic off, so that now
after you throw a rock it never changes back to 0:
you can't throw again. Next I created a new rule,
that states if K is UP, then Rock Thrown should
change to 0, and Throwing Rock is false
Whilst this did space out the spawning of
the rocks, it didn't stop them endlessly
spawning with the key pressed down.
Squid can only throw a second
rock if the attribute is 0. After
firing once it changes to 1. It only
changes back to 0 if the K key goes
up. The rock throwing is limited to
one rock spawning until you
release the K key and press it
again.
2. Whilst the rock mechanic was all fixed, this
method didn’t quite work with the animation
and so needed adjustment. What was happening
was that Throwing Rock was being set to false
upon the key going up, stopping the animation.
This meant that it didn’t run to completion,
often just showing the first frame before being
cut off.
So first I took that change attribute out of the
Throw again rule, as clearly that wasn’t working.
I then made a timer in the Throwing rule, much like the
timer that originally re-set the attributes. I made it re-set
the Throwing Rock attribute after 0.3 seconds. No the
animation plays out even after the K key goes up.
It’s the same set up as before, except now it only resets
the animation attribute, ending the animation, and the
attribute that controls weather or not the player can
throw a rock is reset in a different rule.