Quake DeveLS - Player Speeds

Author: John Rittenhouse
Difficulty: Easy

I feel the need...

Okay everyone has been wondering how to have different player speeds I figured out how. I finally have finished testing everything and getting all to work correctly. Alright paste this code below in "p_client.c" right after the declaritions in "void ClientThink (edict_t *ent, usercmd_t *ucmd)".

	float ClassSpeedModifer, t;
	vec3_t velo;
	vec3_t  end, forward, right, up,add;
	ClassSpeedModifer = ent->ClassSpeed * 0.2;
	//Figure out speed
	VectorClear (velo);
	AngleVectors (ent->client->v_angle, forward, right, up);
    VectorScale(forward, ucmd->forwardmove*ClassSpeedModifer, end);
	VectorAdd(end,velo,velo);
	AngleVectors (ent->client->v_angle, forward, right, up);
    VectorScale(right, ucmd->sidemove*ClassSpeedModifer, end);
	VectorAdd(end,velo,velo);
	//if not in water set it up so they aren't moving up or down when they press forward
	if (ent->waterlevel == 0)
		velo[2] = 0;
	if (ent->waterlevel==1)//feet are in the water
	{
		//Water slows you down or at least I think it should
		velo[0] *= 0.875;
		velo[1] *= 0.875;
		velo[2] *= 0.875;
		ClassSpeedModifer *= 0.875;
	}
	else if (ent->waterlevel==2)//waist is in the water
	{
		//Water slows you down or at least I think it should
		velo[0] *= 0.75;
		velo[1] *= 0.75;
		velo[2] *= 0.75;
		ClassSpeedModifer *= 0.75;
	}
	else if (ent->waterlevel==3)//whole body is in the water
	{
		//Water slows you down or at least I think it should
		velo[0] *= 0.6;
		velo[1] *= 0.6;
		velo[2] *= 0.6;
		ClassSpeedModifer *= 0.6;
	}
	if (ent->groundentity)//add 
		VectorAdd(velo,ent->velocity,ent->velocity);
	else if (ent->waterlevel)
		VectorAdd(velo,ent->velocity,ent->velocity);
	else
	{
		//Allow for a little movement but not as much
		velo[0] *= 0.25;
		velo[1] *= 0.25;
		velo[2] *= 0.25;
		VectorAdd(velo,ent->velocity,ent->velocity);
	}
	//Make sure not going to fast. THis slows down grapple too
	t = VectorLength(ent->velocity);
	if (t > 300*ClassSpeedModifer || t < -300*ClassSpeedModifer)
	{
		VectorScale (ent->velocity, 300 * ClassSpeedModifer / t, ent->velocity);
	}

	//Set these to 0 so pmove thinks we aren't pressing forward or sideways since we are handling all the player forward and sideways speeds
	ucmd->forwardmove = 0;
	ucmd->sidemove = 0;
You now need to define ClassSpeed in "g_local.h" so add at the bottom of the edict_t declarations this
	int ClassSpeed;
Alright you will need to set ClassSpeed to a number somewhere. If I did this right 5 should be normal speed, 0 will be stopped. You could also set up some other stuff so instead of a variable on the edict it is controlled by a console variable but this is not necessary. I think I got most of the bugs worked out but it seems whenever the ClassSpeed is 0 or real slow it seems to make the player view spot move still. I might have forgot some other stuff but I think I got it all.

John Rittenhouse .

This site, and all content and graphics displayed on it,
are ©opyrighted to the Quake DeveLS team. All rights received.
Got a suggestion? Comment? Question? Hate mail? Send it to us!
Oh yeah, this site is best viewed in 16 Bit or higher, with the resolution on 800*600.
Thanks to Planet Quake for their great help and support with hosting.
Best viewed with Netscape 4