the 30 targets is highlighted
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded){
//We are grounded, so recalculate
//move direction direatly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"),0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
//Apply gravity
moveDirection.y = gravity * Time.deltaTime;
//Move the controller
controller.Move(moveDirection * Time.deltaTime;
}
Without you saying what is wrong it is hard to help you, but something I do see is even though you are setting moveDirection.y = jumpspeed on input jump you are overrighting it with the gravity.
try changing this
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
//Apply gravity
moveDirection.y = gravity * Time.deltaTime; //deltaTime is not needed since you are not changing moveDirection.y by gravity but setting it to gravity
to this
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
else{
//Apply gravity
moveDirection.y = gravity;
}
I would also interpolate y back to gravity by doing
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
else{
moveDirection.y = 0; // set to 0 when grounded so you interpolate to the fall speed
}
}
else{
//Apply gravity
moveDirection.y = Mathf.Lerp(moveDirection.y, gravity, Time.deltaTime);// add lerpSpeed * Time.deltaTime to change how fast it lerps
}
*Edit: Also Gravity should be -20 not 20