#pragma strict
var jumps:AudioClip;
var stopfoot :AudioSource;
var speed =40;
var jumpSpeed : float = 10.0f;
var controller : CharacterController ;
var turnSpeed: float = 90; // degrees per second
private var moveDirection : Vector3;
function Start()
{
controller= GetComponent(CharacterController);
}
function Update() {
if(Input.GetKeyDown(KeyCode.RightArrow))
transform.Rotate(0, turnSpeed, 0);
if(Input.GetKeyDown(KeyCode.LeftArrow))
transform.Rotate(0, -turnSpeed, 0);
moveDirection = Vector3(Input.GetAxis("Horizontal")*10, 1,
speed);
if (controller.isGrounded)
{
if(Input.GetKeyDown(KeyCode.Space))
{
moveDirection.y=jumpSpeed;
Debug.Log("jump");
}
}
moveDirection *= speed;
if(!controller.isGrounded)
{
moveDirection.y -= 5*Time.deltaTime;
Debug.Log("gravity");
}
controller.SimpleMove(moveDirection * Time.deltaTime);
}
function jump() {
audio.Stop();
audio.PlayOneShot(jumps);
animation.Play("jump_pose");
yield WaitForSeconds(1f);
animation.Play("run");
}
if(transform.position.y<=490)
{
Destroy(this.gameObject);
}
tried adding velocity and not using gravity,non of them works.
this is an infinite runner,with player moving constantly with rigid body attach to it.