Creating a sprint button

Hey guys, small problem here, why doesn’t my character movement script allow me to make a sprint button :

var speed = 10.0;
var rotation = 100.0;

function Update () {

var speed = Input.GetAxis ("Vertical") * -speed;
var rotation = Input.GetAxis ("Horizontal") * rotationSpeed;

speed *= Time.deltaTime;
rotation *= Time.deltaTime;

transform.Translate (0, 0, translation);
transform.Rotate (0, rotation, 0);

if(Input.GetButtonDown("sprint"))
     var speed = Input.GetAxis ("Vertical") * -speed * 1.5
      var rotation = Input.GetAxis ("Horizontal") * rotationSpeed* 1.5;
	 
}

Can anyone help me ?

Here’s how I modified FPSWalker.js to include run/sprint. This one works, take from it what you need:

		moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
		moveDirection = transform.TransformDirection(moveDirection);
		var mySpeed = WalkSpeed;

		if (Input.GetButton("Run")) {
			mySpeed = RunSpeed;
		}
		moveDirection *= mySpeed;

The reason your first script isn’t working, is that you only modify your speed value after you have applied your movement. To get your script from above working, try this:

var speed = 10.0; 
var rotation = 100.0; 

function Update () { 

var speed = Input.GetAxis ("Vertical") * -speed * Time.deltaTime; 
var rotation = Input.GetAxis ("Horizontal") * rotationSpeed * Time.deltaTime; 

// The if statement applies to more than one line of code, so wrap them in curly braces
// You also don't need to do all your other calculations again.
if(Input.GetButtonDown("sprint")) 
{
     var speed *= 1.5;
     var rotation *= 1.5; 
}

// These calls need to come AFTER all your calculations have been made.
transform.Translate (0, 0, translation); 
transform.Rotate (0, rotation, 0);     
}

Well, I tried just what you said and it still doesn’t work :

var speed = 10.0;
var rotation = 100.0;

function Update () {

if(Input.GetButtonDown("Sprint"))
{
     speed = 15;
      rotation = 150;
}

var movement = Input.GetAxis ("Vertical") * -speed * Time.deltaTime;
var rotation= Input.GetAxis ("Horizontal") * rotation * Time.deltaTime;
}

[/code]

lemme see if i undestand this…

as long as the player keep the sprint button pressed the speed of the character will be increased… but if the player dont touch the arrow keys, even if hes holding the sprint button… the character will stand still right?

wel… i have a diferent question… how do i make my character automaticly sprint… or , rush forward like… 2 metters, only by pressing the sprint button without toching the arrows?