Game Development Reference
In-Depth Information
3. We continue to follow the pattern we have used in
GameCharacterControl
and use Booleans to define whether an action should happen and then handle any
changes in the
update
method. So, let's start by adding three new Booleans to
handle leaning as follows:
private boolean leanLeft, leanRight, leanFree;
4. Now, before we add the actual leaning functionality, we need to introduce two
more fields. The
leanValue
field stores the current amount of leaning for the
character. We use the
maxLean
field to have some kind of limit to how much the
player can lean. This is in radians and is set to corresponding 22.5 degrees.
Sounds too little? Feel free to experiment using the following lines of code: