Code: Select all
// borrowed from:
// http://answers.unity3d.com/questions/20261/how-can-i-make-double-jump-need-help.html
var WalkSpeed = 6.0;
var RunSpeed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
var direction=0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
// moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = new Vector3(Input.GetAxis("Horizontal")*-1,0,0);
moveDirection = transform.TransformDirection(moveDirection);
var mySpeed = WalkSpeed;
/*
if (Input.GetKey("left shift")) {
mySpeed = RunSpeed;
}
*/
moveDirection *= mySpeed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
direction=Input.GetAxis("Horizontal")*-1;
GameObject.Find ("GUI Text").guiText.text="wow!: ".direction;
//.moveDirection;
}
@script RequireComponent(CharacterController)
// character controller heigh = 0.85
// radius = 0.4
Code: Select all
moveDirection = new Vector3(Input.GetAxis("Horizontal")*-1,0,0);