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);
}
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?