im using the firstperson script when space is clicked the player jumps dos anyone know how i can add if the button is held down the player jumps higher
static var thirdperson:boolean=true;
var speed = 6.0; var jumpSpeed = 8.0; var gravity = 20.0;
static var run:boolean = true;
private var moveDirection = Vector3.zero; private var grounded : boolean = false;
function FixedUpdate() { if(thirdperson) { speed = 5; if(run){ var CPH = GetComponent("CPH"); if(Input.GetButton("shift")){ speed = 10; CPH.energy -=20 * Time.deltaTime; } } if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButtonDown ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
} }
@script RequireComponent(CharacterController)