Game Development Reference
In-Depth Information
There's moreā€¦
If you press forward and then rotate the camera, the character will move in that direction,
instead. In many games of this type, however, the character would keep running in the dir-
ection it had before the player rotated the camera. We can apply this behavior to our char-
acter with a few tweaks.
To do this, we need to change modelForwardDir and modelLeftDir into private
fields in the class. Then, we make sure we only update these when the character isn't re-
ceiving any input from the player. In this recipe, this would mean an if statement, as fol-
lows:
if(!forward && !backward && !leftStrafe && !rightStrafe){
modelForwardDir =
cam.getRotation().mult(Vector3f.UNIT_Z).multLocal(1, 0, 1);
modelLeftDir = cam.getRotation().mult(Vector3f.UNIT_X);
}
Search WWH ::




Custom Search