Code snippet: player speed in dependence of health


(nUllSkillZ) #1

Hi,

I had the idea to change the speed of the player in dependence of his health.
(Originally I also wanted to change the field of view in dependence oh health by blending from a clear oval in the center of the screen to zero tranparency and red-/black-color at the borders of the screen).
I changed source but it wasn’t playable.

EDIT:
If you run out of health the player isn’t moving araound at all.

May be someone has a better idea to use the changed code:
Source-file: bg_pmove.c
Function: PM_CmdScale
Starting with line 533:


	if (gametype == GT_SINGLE_PLAYER || gametype == GT_COOP) {
		// Adjust the movespeed
		scale *= (((float) movespeed)/(float) 127);

	} // if (gametype == GT_SINGLE_PLAYER)...

//+ ***** MYMOD *****
	//LINEARITY ONLY FOR TESTING SHOULD BE E.G. SQR
	//DIVIDING BY 100 FOR TESTING SHOULD BE MAXIMUM AVAILABLE HEALTH
	scale = scale * pm->ps->stats[ STAT_HEALTH ] / 100;
//- ***** MYMOD *****

	return scale;
}


(sniser) #2

instead of

scale = scale * pm->ps->stats[ STAT_HEALTH ] / 100;

try

scale = scale * ((float) pm->ps->stats[ STAT_HEALTH ] / pm->ps->stats[ STAT_MAX_HEALTH ]);

?


(nUllSkillZ) #3

Thanks for this tip.
I changad the added source a little bit.
With this change the player will have still some speed at 0 HP:


	if (gametype == GT_SINGLE_PLAYER || gametype == GT_COOP) {
		// Adjust the movespeed
		scale *= (((float) movespeed)/(float) 127);

	} // if (gametype == GT_SINGLE_PLAYER)...

//+ ***** MYMOD *****
	//CHANGED: FUNCTION: SCALE = SCALE * [(1-A) * HEALTH/MAX_HEALTH + A]
	//WITH A AS FACTOR AT 0 HEALTH e.g. FOR 3/4 OF ORIGINAL SPEED AT 0 HEALTH A HAS TO BE REPLACED BY 0.75
	scale = scale * ((float) 0.8 + (1 - 0.8) * pm->ps->stats[ STAT_HEALTH ] / pm->ps->stats[ STAT_MAX_HEALTH ]);
//- ***** MYMOD *****

	return scale;
}


(wizza) #4

am i missing something here?
how can u move at 0hp when your dead?


(nUllSkillZ) #5

My mistake, meant with 1 HP.


(Fusen) #6

interesting but try and balance out medic’s as this will just turn the team into 5 meds 1 engineer


Ford Type 9 Transmission


(Hewster) #7

Indeed, this is critical with this kind of change.

My solution in The WildWest was to give all classes a regen, upto a max of 70 Hp.

After Many hours of intensive testing we found a nice balance between the
speed reduction / regain… I also made it so the Doctors could only pickup
Health packs (Doctors bags in WW) every 5 seconds… this helps balance the
Doctor class a bit more :slight_smile:

I also gave Soldiers slightly higher running speed & re-gain compared to other classes
(except Doc’s)

Hewster