1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | ||

Editor: DonovanBaarda
Time: 2012/11/11 14:24:51 GMT-5 |
||

Note: |

changed:-Objectives -========== Introduction ============changed:-Basic Attributes -================ Dynamic Attributes ==================changed:-These H, S, E values could be displayed using bars on a HUD. - -The following constants adjust how quickly you get tired and recover. They are normally constants but could be tweaked per-character based on some endurance attribute:: Additionally, the following dynamic attributes are derived from H and E to represent weight, fraction of muscles damaged by wounds, and fraction of muscles preoccupied by lifting::: M the actors total weight including encumbrance in bodyweights. Smin is the minimum stamina fraction required to lift what the actor is carrying. Smax is the max stamina fraction limit of the muscles not damaged by wounds. The H, S, E values could be displayed using bars on a HUD. The Smin value could be shown using a black min stamina marker on the bottom end of the stamina bar. The Smax value could be indicated as a red max stamina marker on the top end of the stamina bar. Static Attributes ================= The following attributes adjust how quickly you get tired and recover. They are normally constants but could be tweaked per-character based on some endurance attribute::changed:-The following constants adjust the maximum movement rates. They could be constants, class based, or character based on other attributes:: The following attributes adjust the maximum movement rates. They could be constants, class based, or character based on other attributes::changed:-Note that R/(F+R) is the "steady state" or minimum S value reached for constant activity, so the the R/F ratio is important. Studies on muscles show F is 0.008~0.033, R is 0.0026~0.013, and R/F is 0.3~0.5. However running doesn't involve continuously clenching all muscles so F is less. The model closely matches world records for 100m, 200m, 400m, and 800m with R=0.13, F=0.0165, moveMax=12.0. For gameplay reasons speeding it up to F=0.04, R=0.04 might be better. - -For moveMax, record 100m top speeds average about 10m/sec and peak at 12m/sec. Depending on how fast it feels climbMax=10~12m/s should be OK. Note that R/(F+R) is the "steady state" or minimum S value reached for constant running, so the the R/F ratio is important. Studies on muscles show F is 0.008~0.033, R is 0.0026~0.013, and R/F is 0.3~0.5. However running doesn't involve continuously clenching all muscles so F is less. The model closely matches world records for 100m, 200m, 400m, and 800m with R=0.13, F=0.0165, moveMax=12.0. For gameplay reasons speeding it up to F=0.04, R=0.04 might be better. For moveMax, record 100m top speeds average about 10m/sec and peak at 12m/sec. Depending on how fast it feels moveMax=10~12m/s should be OK.changed:-The (unverified) world record for a vertical jump is around 1.5m, but anything over 1m is considered extraordinary, with 0.75m being the average for professional footballers and basketballers. Micheal Jordan could reputedly jump 1.2m. The average taken for a group of typical medical students was 0.56m for men and 0.35m for women. For jumping up onto surfaces the current world standing box jump records are around 1.44m (making that claimed 1.5M vertical jump very questionable), and for running box jumps around 1.74m (1.8m unofficial). Depending on how the game engine handles jumping onto platforms (can you jump and duck at the top to get onto a higher platform?), you may want to use a hero box jump jumpMax=1.8m, or even super-hero/fantasy jumpMax=2m. - -Note that if jumpMax=climbMax and jumpMult=climbMult then it costs the same energy climb and jump per vertical meter. I suggest keeping jumpMult/climbMult = jumpMax/climbMax to keep the cost/meter the same. The (unverified) world record for a vertical jump is around 1.5m, but anything over 1m is considered extraordinary, with 0.75m being the average for professional footballers and basketballers. Micheal Jordan could reputedly jump 1.2m. The average taken for a group of typical medical students was 0.56m for men and 0.35m for women. For jumping up onto surfaces the current world standing box jump records are around 1.44m (making that claimed 1.5M vertical jump very questionable), and for running box jumps around 1.74m (1.8m unofficial). Depending on how the game engine handles jumping onto platforms (can you jump and duck at the top to get onto a higher platform?), you may want to use a hero box jump jumpMax=1.8m, or even super-hero/fantasy jumpMax=2m, otherwise jumpMax=1.5 is a good playability compromise. Model Constants =============== All the following constants affect various parts of the model. I suggest not changing them, and instead changing the static attributes to adjust how fast/slow actors fatigue, recover, and move. The following constant affects the total actor weight in bodyweights including encumbrance::: weightMult = 1.0 # The max sustainable lift in bodyweights. The following constants affect the fraction of muscles required for lifting::: liftExp = 2.0 # can be turned up to delay the onset of encumbrance effects. liftMult = (0.5 * weightMult)**liftExp # can be turned down to reduce the severity of encumbrance effects. The following constants affect the fraction of muscles damaged by wounds::: woundExp = 2.0 # can be turned up to delay the onset of wound effects. woundMult = 1.0 # can be turned down to reduce the severity of wound effects. The following constants affect the relative energy costs of performing actions::: runMult = 1.0 # running cost per moveMax distance every second. walkMult = 4.0 # walking cost per moveMax distance at moveMax speed every second. upMult = 2.0 # climbing up cost per climbMax vertical distance every second. dnMult = 0.4 # climbing down cost per climbMax vertical distance every second. jumpMult = 1.0 # jumping cost per jumpMax vertical distance every jump. The following constants are used to smooth vertical movement and calculate jump speeds::: climbRC = 0.2 # climb rate low-pass filter timeconstant to average vertical movement over the last 0.2 seconds. g = 9.81 # The acceleration from gravity for calculating jumpSpeeds from jumpHeights. A real max lift is about 2x your own body weight, but anything over 1x is unsustainable. I suggest weightMult=1.0 so that the top-half of the encumbrance bar doesn't go unused and give players an unrealistic impression of how much they can carry. If you want you can allow temporary heavy lifts where E > 1.0 (over encumbered) and have them drop it or collapse when S < Smin. Note the largest professional rugby league player is 133Kg, though 100~125Kg is probably more realistic for a big hero's bodyweight. Note setting woundMult > 1.0 means actors will run out of stamina and collapse before they die. The relative energy cost constants are related to the static movement rate attributes of the actor, and relative to the base running cost runMult=1.0. For realistic uphill running you should have climbMax=1.0 upMult=1.0 dnMult=0.2. However, for actual vertical climbing realistic values are climbMax=2.0, upMult=2.0, dnMult=0.4. For playability we keep the vertical climbing costs, but increase the movement speed to climbMax=3.0 upMult=2.0, dnMult=0.4. This means that you burn stamina 2x as fast climbing at 1/4 the speed of running for 8x the cost/meter. I suggest keeping jumpMult/climbMult = jumpMax/climbMax so the cost of climbing and jumping is the same per vertical meter. Weight ====== The actors total weight in bodyweights affects movement speeds and jump heights. It is calculated as:: self.M = 1.0 + weightMult * self.E Encumbrance =========== Encumbrance preoccupies muscles, leaving less available for running/attacking/etc, and there is a minimum stamina required to lift everything you are carrying. These preoccupied muscles are also subtracted from S when considering how fast you can run, hard you can hit etc:: self.Smin = liftMult*self.E^liftExp Note RF implements this as an additional "drain" on S, but that is slightly miss-leading as it is not really damaged/fatigued muscles and thus should not affect fatigue indicators like panting etc.changed:-Wounds are modelled as damaged muscles, reducing your available muscles for running/fighting/etc. It applies a constant "drain" or cap on your stamina. This could be indicated as a red max stamina marker on the top end of the stamina bar:: - - actor.Smax = 1 - woundMult*(1-actor.H)^woundExp - -Where:: - - woundMult=1.0, but can be turned down to reduce the severity of wound effects. - woundExp=2, but can be turned up to delay the onset of wound effects. - Smax is the max stamina fraction limit of the muscles not damaged by wounds. - -Note setting woundMult > 1.0 means actors will run out of stamina and collapse before they die. Wounds are modelled as damaged muscles, reducing your available muscles for running/fighting/etc. It applies a constant "drain" or cap on your stamina:: self.Smax = 1 - woundMult*(1-self.H)^woundExpchanged:- newSmax = 1 - woundMult*(1-actor.H)^woundExp - actor.S += (newSmax - actor.Smax) * actor.S/actor.Smax - actor.Smax = newSmax newSmax = 1 - woundMult*(1-self.H)^woundExp self.S += (newSmax - self.Smax) * self.S/self.Smax self.Smax = newSmaxchanged:-Encumbrance -=========== - -Encumbrance preoccupies muscles, leaving less available for running/attacking/etc, and there is a minimum stamina required to lift everything you are carrying. It can be shown using a black min stamina marker on the bottom end of the stamina bar. These preoccupied muscles are also subtracted from S when considering how fast you can run, hard you can hit etc:: - - actor.Smin = liftMult*actor.E^liftExp - -Where:: - - liftMult = (0.5 * encumbMult)^liftExp = 0.25, but can be turned down to reduce the stamina burn from encumbrance. - liftExp = 2, but can be turned up to delay the onset of stamina burn from encumbrance. - Smin is the minimum stamina fraction required to lift what the actor is carrying. - -Note RF implements this as an additional "drain" on S, but that is slightly miss-leading as it is not really damaged/fatigued muscles and thus should not affect fatigue indicators like panting etc. Climbing ======== Moving on a gradient affects movement speeds and stamina burn rates. The climbRate can be calculated from the surface gradient directly, or from movement over the last frame. Because vertical movement is so expensive, a small amount of jitter/bob in the actors movement can translate into a huge stamina burn. To avoid this we low-pass filter the calculated climb rate to give the average vertical movement over the last 0.2 seconds. You need to be wary of things like lifts to ensure that dz changes from going up/down on lifts doesn't burn stamina and make actors collapse. RF detects this by checking the actor is running/walking and the gradient is not too steep:: dd = math.sqrt(dz*dz + dx*dx + dy*dy) if (dd > 0.0) and (self.isRunning or self.isWalking): # We can calculate climbRate either from movement or from the surface angle if known. # climbRateNow = sin(climbAngle) * (self.moveMax/self.climbMax) climbRateNow = (dz / dd) * (self.moveMax/self.climbMax) else: climbRateNow = 0.0 self.climbRate = (dt*climbRateNow + climbRC*self.climbRate)/(dt + climbRC) Where:: dx,dy,dz is x,y,z travel distance in the last frame. dd is total travel distance in the last frame. climbAngle is the elevation angle of the direction travelled. dt is the time since the last frame. climbRateNow is the climb rate this frame. climbRate is the average climb rate for the past 0.2 seconds . Note that climbRate is in climbMax vertical distances moved per moveMax total distances moved so that it can be used directly with the energy cost tuning constants. From the climbRate we can calculate the factors for the vertical movement cost, the movement cost, and the movement speed::: climbMult = max(upMult*self.climbRate, -dnMult*self.climbRate) climbMoveMult = 1.0/(self.climbRate**2 + 1.0) climbSpeedMult = 1.0/(climbMult/upMult + climbMoveMult) Where:: climbMult is the vertical movement cost for the gradient. climbMoveMult is a scaling factor on horizontal movement cost for the gradient. climbSpeedMult is a scaling factor on movement speed for the gradient.changed:-This is is how stamina is recovered and burned when standing/walking/running, and movement speed varies with stamina and encumbrance. We use the following tunable constants:: - - encumbMult = 1.0, the "max" lift in number of your own body weights when E=1.0. - upMult=10.0, is the cost of climbing up per meter relative to other things. - downMult=upMult/5=2.0, is the cost of going down per meter relative to other things. - runMult=1.0 is the cost of running relative to other things. - walkMult=4.0 is the cost of walking relative to other things. - runSpeedMult=1.0 is the max running speed as a fraction of moveMax. Can be turned down to reduce running speed and stamina burn. - walkSpeedMult=0.2 is max walking speed as a fraction of moveMax. Can be adjusted to change walking speed and stamina burn. - moveMax=10.0 is the maximum flat running speed in meters/sec. - -A real max lift is about 2x your own body weight, but anything over 1x is unsustainable. I suggest encumbMult=1.0 so that the top-half of the encumbrance bar doesn't go unused and give players an unrealistic impression of how much they can carry. If you want you can allow temporary heavy lifts where E > 1.0 (over encumbered) and have them drop it or collapse when S < Smin. Note the largest professional rugby league player is 133Kg, though 100~125Kg is probably more realistic for a big hero's bodyweight. - -Studies on walking/running on gradients show going uphill/downhill is about 12.5x/2.5x as expensive/meter as running horizontally, so upMult=12.5, downMult=2.5. Record 15m speed climbing top speed is 6.26sec, or about 2m/sec, compared to 100m record top speeds of about 12m/sec, which suggests climbing vertically uses only ~6x the energy as horizontal running and half as much as uphill running. I suspect that climbing using both arms and legs allows double the power output compared to running with just legs, but the energy/meter is the same. It often surprises players how much affect climbing really has, and games tend to have exaggerated gradients. For playability I suggest lower values like upMult=10.0 and downMult=2.0, or even upMult=6.0 and downMult=1.2. - -You can adjust runSpeedMult down to allow a slower run with less stamina burn. Using runSpeedMult=1.0 means run as fast as possible. Using runspeed=0.5 would be equivalent to a marathon runners fast jog at ~5m/s. - -You can adjust walkSpeedMult to allow faster/slower walking with more/less stamina burn. Using walkSpeedMult=0.25 represents a realistic maximum fast walking speed of ~2.5m/sec. Realistic minimum energy walk speed is walkSpeedMult=0.125, but would probably try the patience of gamers. Using walkSpeedMult=0.2 is a brisk walking speed of ~2m/sec, and is a good gaming compromise between energy saving and speed. - -For moveMax, record 100m top speeds average about 10m/sec and peak at 12m/sec. A realistic maximum running speed (for a hero) would be about 10m/sec. - -We calculate the movement speeds and stamina burns each frame like this:: - - onFrame(dt): - M = 1.0 + encumbMult*E - Smax = 1 - woundMult*(1-H)^woundExp - Smin = liftMult*E^liftExp - Srest = (Smax - S) - if isStanding: - Slift = Smin - else: - Slift = 0.0 - climbMult = max(upMult*climbRate, -downMult*climbRate) - moveMult = 1.0/((climbRate/0.1)^2 + 1.0) - moveSpeedMult = 1.0/(climbMult + moveMult) - if isRunning: - moveScale = moveSpeedMult * runSpeedMult * (S-Smin)/M - Smove = moveMult * runMult * M * moveScale - elif isWalking: - moveScale = moveSpeedMult * walkSpeedMult * sqrt((S-Smin)/M) - Smove = moveMult * walkMult * M * moveScale^2 - else: - moveScale = 0.0 - Smove = 0.0 - Sclimb = climbMult * M * moveScale - dS = (R*Srest - F*(Slift + Smove + Sclimb)) * dt - S = S + dS The cost of running per meter is constant, which means if varies linearly with speed. The cost of walking per meter varies with speed, so it varies to the square of speed. This means walking gets cheaper the slower you go. At about 2.5m/second walking is the same cost per meter as running, so any faster than that it is more efficient to run. At about 1.25m/second walking is 1/2 the cost per meter as running. In this model we approximate it as 1/4 moveMax is when walking=running cost, and 1/8 moveMax is when it's 1/2 the cost. Combining in the gradient effects we calculate the stamina burn and speed each frame:: # Calc the running/walking speed multipliers. runSpeedMult = self.moveEffortMult*(self.S-self.Smin)/self.M walkSpeedMult = math.sqrt(runMult/walkMult * runSpeedMult) # Calculate the running/walking state by comparing movement speeds. self.isRunning = runSpeedMult > walkSpeedMult self.isWalking = not self.isRunning and walkSpeedMult > 0.0 # Calc the fraction of muscles used for lifting. if self.isStanding: Slift = self.Smin else: Slift = 0.0 # Calculate move speed scale and fraction of muscles used for moving. if self.isRunning: moveScale = climbSpeedMult * runSpeedMult Smove = climbMoveMult * runMult * self.M * moveScale elif self.isWalking: moveScale = climbSpeedMult * walkSpeedMult Smove = climbMoveMult * walkMult * self.M * moveScale**2 else: moveScale = 0.0 Smove = 0.0 # Calc the fraction of muscles used for climbing. Sclimb = climbMult * self.M * moveScale # Calc fraction of undamaged, fatigued muscles that are resting. Srest = (self.Smax - self.S) # Calc the moveSpeed and adjust S for the frame. self.moveSpeed = moveScale * self.moveMax self.S += (self.staminaReturn*Srest - self.staminaBurn*(Slift + Smove + Sclimb)) * dtchanged:- M is the actor's total weight in bodyweights. - Srest is the fraction of all muscles that are fatigued and resting. moveEffortMult is the fraction of effort spent on moving. runSpeedMult is the running speed factor for effort, stamina, and weight. walkSpeedMult is the walking speed factor for effort, stamina, and weight. moveScale is movement speed as a fraction of moveMax.changed:- climbRate is vertical movement per total distance moved. - climbMult is the cost of climbing based on the gradient. - moveSpeedMult is the scaling factor for movement speeds walking/running for the gradient. - moveMult is the scaling factor for cost of walking/running for the gradient. - moveScale is movement speed as a fraction of moveMax. Srest is the fraction of muscles that are fatigued and resting.changed:- dt is the time since the last frame. - dS is the change in S for this frame. For a given level of effort, we pick to either walk or run based on which would be faster. Use moveEffortMult=1.0 to go as fast as possible, and moveEffortMult=0.16 for an efficient but not too slow walk.removed:- -The climbRate can be calculated from the surface gradient directly, or from movement over the last frame. It should probably be low-pass filtered so jitter/bob doesn't burn fatigue like crazy. This is done by actually calculating it with:: - - dd = sqrt(dz^2 + dy^2 + dz^2) - if dd > 0.0 and isRunning or isWalking: - climbRateNow = dz/dd = sin(climbAngle) - else: - climbRateNow = 0.0 - climbRate = (dt*climbRateNow + climbRC*climbRate)/(dt + climbRC) - -Where:: - - dx,dy,dz is x,y,z travel distance in the last frame. - dd is total travel distance in the last frame. - climbAngle is the elevation angle of the direction travelled. - climbRC = 0.5, is the climbRate lowpass filter time-constant. Can be tweaked to adjust smoothing. - -You also need to be wary of things like lifts to ensure that dz changes from going up/down on lifts doesn't burn fatigue and make actors collapse. RF detects this by checking the actor is running/walking and the gradient is not too steep.changed:- attackDamage = weaponDamage * (actor.S - actor.Smin) - attackSpeed = weaponSpeed * sqrt(actor.S - actor.Smin) attackDamage = weaponDamage * (self.S - self.Smin) attackSpeed = weaponSpeed * sqrt(self.S - self.Smin)changed:- actor.S -= actor.F * attackMult * attackDamage - -Where:: self.S -= self.F * attackMult * attackDamage Where::changed:- blockDamage = max(attackDamage, weaponBlock * (actor.S - actor.Smin)) - blockSpeed = weaponSpeed * sqrt(actor.S - actor.Smin) blockDamage = max(attackDamage, weaponBlock * (self.S - self.Smin)) blockSpeed = weaponSpeed * sqrt(self.S - self.Smin)changed:- actor.S -= actor.F * blockMult * blockDamage - actor.health -= attackDamage - blockDamage - -Where:: self.S -= self.F * blockMult * blockDamage self.health -= attackDamage - blockDamage Where::

The RealisticFatigue? document was a bit too messy and Oblivion specific. This is an attempt to tidy and simplify it into something that can be used for other games. In particular, "stamina" is a better name than "fatigue".

This is an attempt to define a simple model of how health, encumbrance, stamina, and gradients affect movement and physical actions for games. It is based on realistic models and research, but simplified and easy to tune for playability vs realism. The recommended tuning is a compromise that sacrifices realism for playability to make stamina a fun tactical element without being an annoying limitation.

It is based on modelling the short-term energy stored in muscles that burns with physical activity and restores from other longer-term energy sources and respiration within minutes. It does not model longer-term effects like running to collapse, metabolising food, or sleep deprivation, but it could be extended to include them.

Health is modelled as a measure of how much damage can be taken before death, and is translated into a fraction of muscles that are damaged and cannot be applied to physical actions.

Stamina is modelled as the fraction of unfatigued and undamaged muscles available for performing physical actions. All physical actions burn stamina and are affected by the amount of stamina available.

Encumbrance is modelled as the fraction of a maximum sustainable lift being carried, and is translated into a fraction of muscles that are preoccupied with lifting and cannot be applied to other actions. Lifting also burns stamina, and contributes to the actors total weight which affects movement.

The effects of gradients on movement are taken into account for calculating movement speeds and stamina burned.

There is a python implementation of this model available at http://minkirri.apana.org.au/~abo/projects/oblivion/StaminaModel/. Note this model is more up to date than this description.

The following attributes are in the range 0.0 (empty) to 1.0 (full). Note that there can be underlying health/strength/endurance/etc attributes that translate these into different numbers, but from the fatigue models point of view, the only thing that matters is the fraction of full health/stamina/encumbrance:

H is the fraction of life remaining after taking damage. S is the fraction of un-damaged, un-fatigued muscles available for lifting/moving/fighting/etc. E is the fraction of max lift worth of equipment currently carried.

Additionally, the following dynamic attributes are derived from H and E to represent weight, fraction of muscles damaged by wounds, and fraction of muscles preoccupied by lifting::

M the actors total weight including encumbrance in bodyweights. Smin is the minimum stamina fraction required to lift what the actor is carrying. Smax is the max stamina fraction limit of the muscles not damaged by wounds.

The H, S, E values could be displayed using bars on a HUD. The Smin value could be shown using a black min stamina marker on the bottom end of the stamina bar. The Smax value could be indicated as a red max stamina marker on the top end of the stamina bar.

The following attributes adjust how quickly you get tired and recover. They are normally constants but could be tweaked per-character based on some endurance attribute:

F = staminaBurn = 0.04, the rate active muscles fatigue in fraction/second. R = staminaReturn = 0.04, the rate fatigued muscles recover in fraction/second.

The following attributes adjust the maximum movement rates. They could be constants, class based, or character based on other attributes:

moveMax = 12.0, max flat running speed in m/s. climbMax = 3.0, max vertical climbing speed in m/s. jumpMax = 1.5, max vertical jump height in m.

Note that R/(F+R) is the "steady state" or minimum S value reached for constant running, so the the R/F ratio is important. Studies on muscles show F is 0.008~0.033, R is 0.0026~0.013, and R/F is 0.3~0.5. However running doesn't involve continuously clenching all muscles so F is less. The model closely matches world records for 100m, 200m, 400m, and 800m with R=0.13, F=0.0165, moveMax=12.0. For gameplay reasons speeding it up to F=0.04, R=0.04 might be better.

For moveMax, record 100m top speeds average about 10m/sec and peak at 12m/sec. Depending on how fast it feels moveMax=10~12m/s should be OK.

Studies on walking/running on gradients show going uphill is about 12.5x as expensive/meter as running horizontally, so realistically climbMax=moveMax/12.5. However, record 15m speed climbing top speed is 6.26sec, or about 2m/sec, compared to 100m record top speeds of about 12m/sec, which suggests climbing vertically uses only ~6x the energy as horizontal running and half as much as uphill running. I suspect that climbing using both arms and legs allows nearly double the power output compared to running with just legs, but the energy/meter is the same, so once you run down the energy stored in your muscles and are limited by respiration, you would slow to the expected 1/12.5 climbing rate. It often surprises players how much affect climbing really has, and games tend to have exaggerated gradients. For playability I suggest climbMax=2.0~4.0m/s.

The (unverified) world record for a vertical jump is around 1.5m, but anything over 1m is considered extraordinary, with 0.75m being the average for professional footballers and basketballers. Micheal Jordan could reputedly jump 1.2m. The average taken for a group of typical medical students was 0.56m for men and 0.35m for women. For jumping up onto surfaces the current world standing box jump records are around 1.44m (making that claimed 1.5M vertical jump very questionable), and for running box jumps around 1.74m (1.8m unofficial). Depending on how the game engine handles jumping onto platforms (can you jump and duck at the top to get onto a higher platform?), you may want to use a hero box jump jumpMax=1.8m, or even super-hero/fantasy jumpMax=2m, otherwise jumpMax=1.5 is a good playability compromise.

All the following constants affect various parts of the model. I suggest not changing them, and instead changing the static attributes to adjust how fast/slow actors fatigue, recover, and move.

The following constant affects the total actor weight in bodyweights including encumbrance::

weightMult = 1.0 # The max sustainable lift in bodyweights.

The following constants affect the fraction of muscles required for lifting::

liftExp = 2.0 # can be turned up to delay the onset of encumbrance effects. liftMult = (0.5 * weightMult)**liftExp # can be turned down to reduce the severity of encumbrance effects.

The following constants affect the fraction of muscles damaged by wounds::

woundExp = 2.0 # can be turned up to delay the onset of wound effects. woundMult = 1.0 # can be turned down to reduce the severity of wound effects.

The following constants affect the relative energy costs of performing actions::

runMult = 1.0 # running cost per moveMax distance every second. walkMult = 4.0 # walking cost per moveMax distance at moveMax speed every second. upMult = 2.0 # climbing up cost per climbMax vertical distance every second. dnMult = 0.4 # climbing down cost per climbMax vertical distance every second. jumpMult = 1.0 # jumping cost per jumpMax vertical distance every jump.

The following constants are used to smooth vertical movement and calculate jump speeds::

climbRC = 0.2 # climb rate low-pass filter timeconstant to average vertical movement over the last 0.2 seconds. g = 9.81 # The acceleration from gravity for calculating jumpSpeeds from jumpHeights.

A real max lift is about 2x your own body weight, but anything over 1x is unsustainable. I suggest weightMult=1.0 so that the top-half of the encumbrance bar doesn't go unused and give players an unrealistic impression of how much they can carry. If you want you can allow temporary heavy lifts where E > 1.0 (over encumbered) and have them drop it or collapse when S < Smin. Note the largest professional rugby league player is 133Kg, though 100~125Kg is probably more realistic for a big hero's bodyweight.

Note setting woundMult > 1.0 means actors will run out of stamina and collapse before they die.

The relative energy cost constants are related to the static movement rate attributes of the actor, and relative to the base running cost runMult=1.0. For realistic uphill running you should have climbMax=1.0 upMult=1.0 dnMult=0.2. However, for actual vertical climbing realistic values are climbMax=2.0, upMult=2.0, dnMult=0.4. For playability we keep the vertical climbing costs, but increase the movement speed to climbMax=3.0 upMult=2.0, dnMult=0.4. This means that you burn stamina 2x as fast climbing at 1/4 the speed of running for 8x the cost/meter. I suggest keeping jumpMult/climbMult = jumpMax/climbMax so the cost of climbing and jumping is the same per vertical meter.

The actors total weight in bodyweights affects movement speeds and jump heights. It is calculated as:

self.M = 1.0 + weightMult * self.E

Encumbrance preoccupies muscles, leaving less available for running/attacking/etc, and there is a minimum stamina required to lift everything you are carrying. These preoccupied muscles are also subtracted from S when considering how fast you can run, hard you can hit etc:

self.Smin = liftMult*self.E^liftExp

Note RF implements this as an additional "drain" on S, but that is slightly miss-leading as it is not really damaged/fatigued muscles and thus should not affect fatigue indicators like panting etc.

Wounds are modelled as damaged muscles, reducing your available muscles for running/fighting/etc. It applies a constant "drain" or cap on your stamina:

self.Smax = 1 - woundMult*(1-self.H)^woundExp

Whenever you are damaged/healed and your health changes, it damages/restores some of both fatigued and unfatigued muscles. There should be a change in S that reflects this. It can be calculated each frame from the change in Smax like this:

newSmax = 1 - woundMult*(1-self.H)^woundExp self.S += (newSmax - self.Smax) * self.S/self.Smax self.Smax = newSmax

Note this ensures that at low stamina a hit winds you a bit, but not too much.

Moving on a gradient affects movement speeds and stamina burn rates. The climbRate can be calculated from the surface gradient directly, or from movement over the last frame. Because vertical movement is so expensive, a small amount of jitter/bob in the actors movement can translate into a huge stamina burn. To avoid this we low-pass filter the calculated climb rate to give the average vertical movement over the last 0.2 seconds. You need to be wary of things like lifts to ensure that dz changes from going up/down on lifts doesn't burn stamina and make actors collapse. RF detects this by checking the actor is running/walking and the gradient is not too steep:

dd = math.sqrt(dz*dz + dx*dx + dy*dy) if (dd > 0.0) and (self.isRunning or self.isWalking): # We can calculate climbRate either from movement or from the surface angle if known. # climbRateNow = sin(climbAngle) * (self.moveMax/self.climbMax) climbRateNow = (dz / dd) * (self.moveMax/self.climbMax) else: climbRateNow = 0.0 self.climbRate = (dt*climbRateNow + climbRC*self.climbRate)/(dt + climbRC)

Where:

dx,dy,dz is x,y,z travel distance in the last frame. dd is total travel distance in the last frame. climbAngle is the elevation angle of the direction travelled. dt is the time since the last frame. climbRateNow is the climb rate this frame. climbRate is the average climb rate for the past 0.2 seconds .

Note that climbRate is in climbMax vertical distances moved per moveMax total distances moved so that it can be used directly with the energy cost tuning constants. From the climbRate we can calculate the factors for the vertical movement cost, the movement cost, and the movement speed::

climbMult = max(upMult*self.climbRate, -dnMult*self.climbRate) climbMoveMult = 1.0/(self.climbRate**2 + 1.0) climbSpeedMult = 1.0/(climbMult/upMult + climbMoveMult)

Where:

climbMult is the vertical movement cost for the gradient. climbMoveMult is a scaling factor on horizontal movement cost for the gradient. climbSpeedMult is a scaling factor on movement speed for the gradient.

The cost of running per meter is constant, which means if varies linearly with speed. The cost of walking per meter varies with speed, so it varies to the square of speed. This means walking gets cheaper the slower you go. At about 2.5m/second walking is the same cost per meter as running, so any faster than that it is more efficient to run. At about 1.25m/second walking is 1/2 the cost per meter as running. In this model we approximate it as 1/4 moveMax is when walking=running cost, and 1/8 moveMax is when it's 1/2 the cost. Combining in the gradient effects we calculate the stamina burn and speed each frame:

# Calc the running/walking speed multipliers. runSpeedMult = self.moveEffortMult*(self.S-self.Smin)/self.M walkSpeedMult = math.sqrt(runMult/walkMult * runSpeedMult) # Calculate the running/walking state by comparing movement speeds. self.isRunning = runSpeedMult > walkSpeedMult self.isWalking = not self.isRunning and walkSpeedMult > 0.0 # Calc the fraction of muscles used for lifting. if self.isStanding: Slift = self.Smin else: Slift = 0.0 # Calculate move speed scale and fraction of muscles used for moving. if self.isRunning: moveScale = climbSpeedMult * runSpeedMult Smove = climbMoveMult * runMult * self.M * moveScale elif self.isWalking: moveScale = climbSpeedMult * walkSpeedMult Smove = climbMoveMult * walkMult * self.M * moveScale**2 else: moveScale = 0.0 Smove = 0.0 # Calc the fraction of muscles used for climbing. Sclimb = climbMult * self.M * moveScale # Calc fraction of undamaged, fatigued muscles that are resting. Srest = (self.Smax - self.S) # Calc the moveSpeed and adjust S for the frame. self.moveSpeed = moveScale * self.moveMax self.S += (self.staminaReturn*Srest - self.staminaBurn*(Slift + Smove + Sclimb)) * dt

where:

moveEffortMult is the fraction of effort spent on moving. runSpeedMult is the running speed factor for effort, stamina, and weight. walkSpeedMult is the walking speed factor for effort, stamina, and weight. moveScale is movement speed as a fraction of moveMax. Slift is the fraction of all muscles applied to lifting. Smove is the fraction of all muscles applied to moving. Sclimb is the fraction of all muscles applied to climbing. Srest is the fraction of muscles that are fatigued and resting. moveSpeed is the movement speed in meters/sec.

For a given level of effort, we pick to either walk or run based on which would be faster. Use moveEffortMult=1.0 to go as fast as possible, and moveEffortMult=0.16 for an efficient but not too slow walk.

If you are not standing and are collapsed, lying down, or sitting, then you are not actually lifting anything so Slift=0.0. We don't make Smin zero in this case to make it clear what your minimum stamina is to stand. The moveSpeed and Smove depend on if you are running or walking.

This is how stamina is burned by jumping, and how jump height varies with stamina and encumbrance:

onJump: jumpScale = (S - Smin)/M jumpHeight = jumpScale * jumpMax jumpVelocity = sqrt(2*g*jumpHeight) dS = -F * jumpMult * (S - Smin) S = S + dS stamina = S*staminaMax

Where:

jumpMult = 1.0, but can be tuned down to reduce encumbrance effects on jumping. jumpScale is the jump height as a fraction of max jump height. jumpMax=1.0 is the maximum unfatigued, unencumbered jump height in meters. jumpHeight is the height of the jump in meters. jumpVelocity is take-off velocity in meters/sec (for physics models). g = 9.81m/s^2 is the gravitational constant.

Using jumpMult=1.0 means a jump burns as much stamina as running for 1 second.

In general, attacking is about hitting your enemy with energy, and blocking is absorbing/deflecting that energy. Stamina is energy, so stamina burned should be proportional to (potential) attack damage. Absorbing energy with a block is like negative work. Studies show negative work is 1/5 the cost of positive work, so blocking should use about 1/5 the stamina of attacking. Blocking is pitting defence energy vs attack energy, so the amount of damage that can be blocked with a given weapon should be about the same as its attack damage, and the rest of the damage gets through. Blocking a big attack with a little block can't deflect all the damage. The amount of damage delivered/deflected with a weapon should be proportional to the available stamina. Attacking/blocking is kinetic energy, which is proportional to V^2, which means attack speed should be proportional to the square-root of available stamina. For balance, the damage * speed for all weapons should be about the same.

This is the basic model, which can then be extended by adding damage, block, speed, and reach factors for different weapons, attacks, etc to take into account some are more effective at attacking/blocking than others.

The speed and effectiveness of attacks depends on available stamina, and also burns stamina:

attackDamage = weaponDamage * (self.S - self.Smin) attackSpeed = weaponSpeed * sqrt(self.S - self.Smin) attackTime = 1/attackSpeed self.S -= self.F * attackMult * attackDamage

Where:

attackMult~=0.5/healthMax is the energy cost of attacking. weaponDamage is the base attack damage for the weapon. weaponSpeed is the base weapon speed in attacks/second. attackDamage is damage dealt from the attack. attackSpeed is attack/block speed in attacks/second, attackTime is the duration of the attack/block in seconds.

For blocks, you could do exactly the same thing, or you could make the block cost depend on the damage blocked:

blockDamage = max(attackDamage, weaponBlock * (self.S - self.Smin)) blockSpeed = weaponSpeed * sqrt(self.S - self.Smin) blockTime = 1/blockSpeed self.S -= self.F * blockMult * blockDamage self.health -= attackDamage - blockDamage

Where:

blockMult~=0.1/healthMax is the energy cost of blocking. weaponBlock is the base block damage for the weapon. weaponSpeed is the base weapon speed in attacks/second. blockDamage is damage dealt from the attack. blockSpeed is attack/block speed in attacks/second, blockTime is the duration of the attack/block in seconds.

The models E,H,S can be calculated from game attributes like this:

E = encumb/encumbMax H = health/healthMax S = stamina/staminaMax

Where:

health is the actors current "health". healthMax is the actors maximum "health". stamina is the actors current "stamina". staminaMax is the actors maximum "stamina". encumb is the actors current encumbrance in equivalent Kg. encumbMax is the actors maximum encumbrance in equivalent Kg.

Note that although encumb is in Kg, it should take into account how awkward things are to carry, not just their weight. Long clumsy or sharp objects should have a higher encumbrance than their raw weight. Putting things in convenient carrying containers like backpacks should reduce awkward objects encumbrance back towards their real weight.