hi guys im having a bit of a problem with my sprint script it doesnt seem to change the movement speed and i cant seem to figure out why can someone see and tell me what i have done wrong pleaese?

public class PlayerComtroller : MonoBehaviour {
public float movementSpeed = 3f;
public float jumpForce = 20f;
public float gravity = 10f;
public float rotationSpeed = 10f;
public float sprintSpeed = 50f;
public bool sprint;

private Rigidbody rb;

private bool isGrounded;
private bool canJump;

// Use this for initialization
void Start () 
{
	rb = GetComponent<Rigidbody>();
}

// Update is called once per frame
void Update ()
{
	

	float horizontal = Input.GetAxis ("Horizontal") * rotationSpeed * Time.deltaTime;
	float vertical = Input.GetAxis ("Vertical") * movementSpeed * Time.deltaTime;

	transform.Rotate (0, horizontal, 0);
	transform.Translate (0, 0, vertical);

	if (Input.GetButtonDown("Jump") && isGrounded) 
		rb.AddForce (new Vector3(0, jumpForce * movementSpeed * Time.deltaTime, 0));

	if(Input.GetKeyDown(KeyCode.LeftShift))
	{
		sprint = true;
	    sprintSpeed = Input.GetAxis ("Vertical") * movementSpeed * sprintSpeed * Time.deltaTime;
	}
		
	if(Input.GetKeyUp(KeyCode.LeftShift))
	{
		sprint = false;
		sprintSpeed = Input.GetAxis ("Vertical") * movementSpeed - sprintSpeed * Time.deltaTime;
	}

}

void OnCollisionEnter (Collision collisionInfo)
	{
		isGrounded = true;
	}

void OnCollisionExit (Collision collisionInfo)
{
	isGrounded = false;

}

}

i believe that your are reading the input for sprint after the rigidbody addforce. You should read for the input before that. And you should also separate the applied speed from the normal and sprint speed. So make a private variable wich is movementSpeed, then use 2 public variables for walking or normal speed and other for run or sprint speed. Then check if the input has happen but before add any force to rigidbody. Then if the input ocurr change movementSpeed to match sprintSpeed, and if there isn’t any input with a simple else statement set it to be normalspeed or walkspeed. Then after done with the checks needed do the rb.addforce stuff.

<
using UnityEngine;
using System.Collections;

public class FPSWalker : MonoBehaviour {

public float WalkSpeed = 6.0F;
public float CrouchSpeed = 3.0F;
public float RunSpeed = 12.0F;

public float jumpSpeed = 8.0F;
public float gravity = 30.0F;
public float SmoothGroundSpeed = 0.8F;
public float SmoothAirBornSpeed = 0.1F;
public Transform MyCamera;

private Vector3 moveDirection = Vector3.zero;
private Vector3 lastDirection = Vector3.zero;

private Vector3 ActualPosition = Vector3.zero;
private Vector3 LastPosition = Vector3.zero;

private CharacterController controller;	
private Transform MyTransform;
private FPSManager FPStatus;

private float GroundedSpeed = 6.0F;
private float AirBornSpeed = 6.0F;
private float AirSpeed;

void Start () {
	controller = GetComponent<CharacterController>();
	FPStatus = GetComponent<FPSManager>();
	MyTransform = transform;
	GroundedSpeed = WalkSpeed;
}

void Update() {
			
	if (controller.isGrounded) {
		if(Input.GetButtonDown("Run") && !FPStatus.IsCrouched == true){
			if(FPStatus.IsRunning == false){
				FPStatus.IsRunning = true;
				GroundedSpeed = RunSpeed;
				AirBornSpeed = RunSpeed;
			}
			else{
				FPStatus.IsRunning = false;
				GroundedSpeed = WalkSpeed;
				AirBornSpeed = WalkSpeed;
			}
		}
		
		if(Input.GetButtonDown("Crouch")){
			if(FPStatus.IsCrouched == false){
				FPStatus.IsCrouched = true;
				FPStatus.IsRunning = false;
				controller.height = 1.0F;
				MyCamera.SendMessage("CrouchMidPoint");
				GroundedSpeed = CrouchSpeed;
				AirBornSpeed = CrouchSpeed;
			}
			else{
				FPStatus.IsCrouched = false;
				controller.height = 2.0F;
				MyCamera.SendMessage("StandMidPoint");
				GroundedSpeed = WalkSpeed;
				AirBornSpeed = WalkSpeed;
			}
		}
	
		if(FPStatus.MoveBtnHold == true){
			moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
			moveDirection = MyTransform.TransformDirection(moveDirection);
			moveDirection *= Mathf.Lerp(0, GroundedSpeed, Time.time);
			ActualPosition = MyTransform.position;
		}
		else{
			moveDirection *= Mathf.InverseLerp(GroundedSpeed, 0, SmoothGroundSpeed);
		}
		
		if (Input.GetButton("Jump")){
			moveDirection.y = jumpSpeed;
		}
		
		FPStatus.IsGrounded = true;
	}
	
	else{
		//AirSpeed = Mathf.InverseLerp(AirBornSpeed, 0, SmoothAirBornSpeed * Time.deltaTime);
		if(FPStatus.MoveBtnHold == true){
			moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
			moveDirection = MyTransform.TransformDirection(moveDirection);
			moveDirection *= Mathf.Lerp(0, AirBornSpeed, Time.time);
	
		}
		else{
			moveDirection *= Mathf.InverseLerp(AirBornSpeed, 0, SmoothAirBornSpeed);
		}
		moveDirection.y = lastDirection.y;
		ActualPosition = MyTransform.position;
		FPStatus.IsGrounded = false;
	}
	
	
	if(LastPosition != ActualPosition){
		FPStatus.IsMoving = true;
	}
	else{
		FPStatus.IsMoving = false;
	}
	LastPosition = ActualPosition;
	
	moveDirection.y -= gravity * Time.deltaTime;
	controller.Move(moveDirection * Time.deltaTime);
	lastDirection = moveDirection;
}

}

This is an example of how i performed the run and walking behaviour to work properly. I read all the inputs first with if and else statements, since is a simple code i didn’t use any fancy solution here. Just a bunch of if and else statements to read all inputs and define how the movement should be performed at the end of the update. I dont remember if the script work fully since i was trying to add a smothness value to the input and that give me a lot of trouble back in the day. Right now i’m using a third party character controller asset so i forget all that stuff. As far as i can tell you could even use that script and modify the code where the movement is performed with charactercontroller component and replace it with a rigidbody movement behaviour.