Advertisement
rhose87

FPSWalkeriPhone

Feb 6th, 2012
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var speed = 4.0;
  2. var jumpSpeed = 8.0;
  3. var gravity = 20.0;
  4.  
  5. private var moveDirection = Vector3.zero;
  6. private var baseDirection : Vector3 = Vector3.zero;
  7.  
  8. private var controller : CharacterController;
  9. private var trans : Transform;
  10. var gyro : Gyroscope;
  11. i
  12. function Start (){
  13.     controller = GetComponent(CharacterController);
  14.     trans = transform;
  15. }
  16.  
  17. function CustomUpdate() {
  18.     var deltaTime = Time.deltaTime;
  19.    
  20.     moveDirection = baseDirection; 
  21.     trans.rotation 
  22.     moveDirection = trans.TransformDirection(moveDirection);
  23.     moveDirection *= speed;
  24.  
  25.     if (moveDirection.sqrMagnitude < 0.1)
  26.         return;
  27.  
  28.     // Apply gravity
  29.     moveDirection.y -= gravity * deltaTime;
  30.    
  31.     // Move the controller
  32.     controller.Move(moveDirection * deltaTime);
  33.    
  34.     gameObject.Find("print1").guiText.text = moveDirection.ToString();
  35. }
  36.  
  37. function SetMoveDirection (moveDir : Vector3){
  38.     baseDirection = moveDir;
  39. }
  40.  
  41. @script RequireComponent(CharacterController)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement