- Home /
wanna know what make my char stop
Hi, I wanna know what part in this code make my char stop move around, I know if I press the key the char gonna move, but I dont understand what's make stop him O.o
var jumpSpeed:float = 8.0; var gravity:float = 20.0; var runSpeed:float = 10.0; var walkSpeed:float = 5.0; private var rotateSpeed:float = 150.0;
private var grounded:boolean = false; private var moveDirection:Vector3 = Vector3.zero; private var isWalking:boolean = false; private var moveStatus:String = "idle";
function Update () { //print(walkSpeed); // Only allow movement and jumps while grounded if(grounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
//moveDirection = new Vector3((Input.GetMouseButton(1) ? Input.GetAxis("Horizontal") : 0),0,Input.GetAxis("Vertical"));
// if moving forward and to the side at the same time, compensate for distance
// TODO: may be better way to do this?
if(Input.GetAxis("Horizontal") && Input.GetAxis("Vertical")) {
moveDirection *= .7;
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= isWalking ? walkSpeed : runSpeed;
//}
moveStatus = "idle";
if(moveDirection != Vector3.zero)
moveStatus = isWalking ? "walking" : "running";
// Jump!
if(Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
if(Input.GetMouseButton(1)) { transform.Rotate(0,Input.GetAxis("Horizontal") rotateSpeed Time.deltaTime, 0); // transform.Rotate(0, Time.deltaTime, 0); } else { transform.rotation = Quaternion.Euler(0,Camera.main.transform.eulerAngles.y,0); }
if(Input.GetMouseButton(1) || Input.GetMouseButton(2)) Screen.lockCursor = false; else Screen.lockCursor = true;
//Apply gravity moveDirection.y -= gravity * Time.deltaTime;
//Move controller var controller:CharacterController = GetComponent(CharacterController); var flags = controller.Move(moveDirection * Time.deltaTime); grounded = (flags & CollisionFlags.Below) != 0; }
@script RequireComponent(CharacterController)
sorry for my poor english, thanks ^^