hi!
I’m working on making some sidescroller thing where the player moves with a constant force.
but when i run the scene with my code the player doesn’t move. but i can jump when i press space.
here’s my code:
var speed: float = 2; // move speed
var jumpSpeed: float = 12; // initial jump speed
var gravity: float = 30;
private var cc: CharacterController;
private var vSpeed: float;
function Update(){
var moveDir = transform.forward * speed; // calculate the horizontal speed
if (!cc) cc = GetComponent(CharacterController); // get the CharacterController
if (cc.isGrounded){ // when grounded...
vSpeed = 0.0; // vSpeed is zero...
if (Input.GetButtonDown("Jump")){ // unless the character jumps
vSpeed = jumpSpeed;
}
}
vSpeed -= gravity*Time.deltaTime; // apply a physically correct gravity
moveDir.y = vSpeed; // add the vertical speed
cc.Move(moveDir*Time.deltaTime); // and finally move the character
}
what have i done wrong?