How to have a sprinting player use up energy
Torque 3D's Player
class has three main modes of movement over land: sprinting, running, and crouching. Some are designed to allow a player to sprint as much as they want, but perhaps with other limitations while sprinting. This is the default method of sprinting in the Torque 3D templates. Other game designs allow the player to sprint only for short bursts before the player becomes "tired". In this recipe, we will learn how to set up the Player
class such that sprinting uses up a pool of energy that slowly recharges over time; and when that energy is depleted, the player is no longer able to sprint.
How to do it...
We are about to modify a PlayerData Datablock
instance so that sprint uses up the player's energy as follows:
Open your player's
Datablock
in a text editor, such as Torsion. The Torque 3D templates have theDefaultPlayerData Datablock
template inart/datablocks/player.cs
.Find the sprinting section of the
Datablock
instance and make the...