Sprinting with Energy Bar Effect
by Infinitum3D · 10/07/2008 (10:49 am) · 3 comments
10-07-2008 Torque 101: setRepairRate
NOTE: Always backup your files first. I can't say this enough. I make many mistakes, and its so much easier to replace a single file than to start the whole process over!!! Read through the entire posting before trying this. I may make a mistake and have to start again!!
I'm following a resource on garagegames called Code: Health repair/recharge rate by Dustin Mullen (Jun 16, 2008)
It allows the player's health to restore gradually (verrrrry slowly) over time. It just a simple mod of player.cs, changing two lines:
First change
repairRate = 0.33;
to
repairRate = 0.001;
then down under
function Armor::onAdd(%this,%obj)
change the setRepairRate from
%obj.setRepairRate(0);
to
%obj.setRepairRate(%this.repairRate);
That's it. Now when Player takes damage, he will slowly heal (regain health) over time.
delete .dso's and restart.
Now, to edit the Sprint function so that energy depletes and gradually returns.
I already have a Sprint function.
I add this:
This may not work in multiplayer mode since it directly affects the PlayerBody datablock.
What I'd really like is to add the Energy amount directly to the equation, like this:
$mvForwardAction = %val * $movementSpeed * ENERGY;
but I haven't figured out the proper syntax yet.
In player.cs I set rechargeRate 0.1
Note: "recharge" is for energy, "repair" is for health.
Back in default.bind.cs, add the change to the [b]moveforward[/b[ function also
So basically, when you sprint, you lose energy, when you stand still, you regain energy, and when you walk, your energy doesn't increase or decrease.
Save player.cs and default.bind.cs, delete dso's, and restart.
Tony
NOTE: Always backup your files first. I can't say this enough. I make many mistakes, and its so much easier to replace a single file than to start the whole process over!!! Read through the entire posting before trying this. I may make a mistake and have to start again!!
I'm following a resource on garagegames called Code: Health repair/recharge rate by Dustin Mullen (Jun 16, 2008)
It allows the player's health to restore gradually (verrrrry slowly) over time. It just a simple mod of player.cs, changing two lines:
First change
repairRate = 0.33;
to
repairRate = 0.001;
then down under
function Armor::onAdd(%this,%obj)
change the setRepairRate from
%obj.setRepairRate(0);
to
%obj.setRepairRate(%this.repairRate);
That's it. Now when Player takes damage, he will slowly heal (regain health) over time.
delete .dso's and restart.
Now, to edit the Sprint function so that energy depletes and gradually returns.
I already have a Sprint function.
//-----------------
function sprint(%val)
{
$mvForwardAction = %val * $movementSpeed * 3;
}
//-----------------I add this:
if (%val)
{
playerbody.runEnergyDrain = 1;
}
else playerbody.runEnergyDrain = 0.2;So that it ends up looking like this:function sprint(%val)
{
$mvForwardAction = %val * $movementSpeed * 3;
if (%val)
{
playerbody.runEnergyDrain = 1;
}
else playerbody.runEnergyDrain = 0.2;
}This may not work in multiplayer mode since it directly affects the PlayerBody datablock.
What I'd really like is to add the Energy amount directly to the equation, like this:
$mvForwardAction = %val * $movementSpeed * ENERGY;
but I haven't figured out the proper syntax yet.
In player.cs I set rechargeRate 0.1
Note: "recharge" is for energy, "repair" is for health.
Back in default.bind.cs, add the change to the [b]moveforward[/b[ function also
function moveforward(%val)
{
$mvForwardAction = %val * $movementSpeed;
if (%val)
{
playerbody.runEnergyDrain = 0.1;//--this is equal to the recharge rate
}
else playerbody.runEnergyDrain = 0;
} So basically, when you sprint, you lose energy, when you stand still, you regain energy, and when you walk, your energy doesn't increase or decrease.
Save player.cs and default.bind.cs, delete dso's, and restart.
Tony
About the author
#2
10/07/2008 (1:27 pm)
Don't just backup, use version control.
#3
Here's a link to Anthony's version, which WILL work in multiplayer.
www.garagegames.com/community/forums/viewthread/80059/
Thanks again Anthony!
05/19/2009 (1:36 pm)
UPDATE:Here's a link to Anthony's version, which WILL work in multiplayer.
www.garagegames.com/community/forums/viewthread/80059/
Thanks again Anthony!

Associate Anthony Rosenbaum