I have one animated character,my requirement is it should run on the top of the buildings and jump form the one building to an other building.Initially I am setting its position on the building, but when I play the game it is running in the air (some gap between the building and the character). Any one help me to fix this.
private var walkSpeed : float = 1.0;
private var gravity = 5;
private var moveDirection : Vector3 = Vector3.zero;
private var charController : CharacterController;
private var jump =0.0;
private var gameOver: boolean =false;
function Start()
{
charController = GetComponent(CharacterController);
animation.wrapMode = WrapMode.Loop;
}
function Update () {
if(charController.isGrounded)
{
Debug.Log("Entered into if");
jump=0.0;
animation.CrossFade("run");
walkSpeed = 1;
if(Input.GetButtonDown("Jump"))
{
jump=2.0;
walkSpeed=2.0;
animation.CrossFade("jump");
}
moveDirection = Vector3(0,jump,walkSpeed);
moveDirection = transform.TransformDirection(moveDirection);
}
moveDirection.y -= gravity * Time.deltaTime;
charController.Move(moveDirection * (Time.deltaTime* walkSpeed) );
//walkSpeed=0;
}