Share Pastebin
Guest
Public paste!

Profas

By: a guest | Nov 2nd, 2009 | Syntax: JavaScript | Size: 2.20 KB | Hits: 386 | Expires: Never
Copy text to clipboard
  1. public var xAxis : boolean = true;
  2. public var zAxis : boolean = true;
  3. public var jumpEnabled : boolean = true;
  4. public var moveInAir : boolean = true;
  5. public var speed : float = 5.0;
  6. public var airSpeed : float = 5.0;
  7. public var jumpSpeed : float = 5.0;
  8. public var gravity : float = 10.0;
  9. public var speedIncreaserEnabled : boolean = true;
  10. public var minSpeed : float = 0.0;
  11. public var maxSpeed : float = 10.0;
  12. public var increaseStepSize : float = 1.0;
  13.  
  14. private var grounded : boolean = false;
  15. private var grounded2 : boolean = false;
  16. private var moveDirection : Vector3 = Vector3.zero;
  17. private var moveDirectionAir : Vector3 = Vector3.zero;
  18. private var getHor = 0.0;
  19. private var getVer = 0.0;
  20. private var manual : boolean = false;
  21.  
  22. function Start()
  23. {
  24.         if(speedIncreaserEnabled) {
  25.                 speed = minSpeed;
  26.         }
  27. }
  28.  
  29. function FixedUpdate()
  30. {
  31.         if(xAxis) {
  32.                 getHor = Input.GetAxis("Horizontal");
  33.         }
  34.                        
  35.         if(zAxis) {
  36.                 getVer = Input.GetAxis("Vertical");
  37.         }
  38.                
  39.         if(speedIncreaserEnabled)
  40.         {
  41.                 if((getHor!=0)||(getVer!=0)) {
  42.                         if(speed<maxSpeed) {
  43.                                 speed+= increaseStepSize;
  44.                         }
  45.                 }
  46.                 else {
  47.                         if(speed>minSpeed) {
  48.                                 speed -= increaseStepSize;
  49.                         }
  50.                 }
  51.                                
  52.                 airSpeed = speed;
  53.         }
  54.        
  55.         if(grounded)
  56.         {
  57.                 moveDirectionAir.x = 0;
  58.                 moveDirectionAir.z = 0;
  59.  
  60.                 moveDirection = new Vector3(getHor, 0, getVer);
  61.                 moveDirection = transform.TransformDirection(moveDirection);
  62.                 moveDirection *= speed;
  63.                
  64.                 if ((Input.GetButton ("Jump"))&&(jumpEnabled)) {
  65.                         moveDirection.y = jumpSpeed;
  66.                 }
  67.         }
  68.         else if(moveInAir)
  69.         {
  70.                 if((getHor>0)||(getHor<0)) {
  71.                         moveDirection.x = 0;
  72.                 }
  73.                        
  74.                 if((getVer>0)||(getVer<0)) {
  75.                         moveDirection.z = 0;
  76.                 }
  77.                        
  78.                 moveDirectionAir = new Vector3(getHor, 0, getVer);
  79.                 moveDirectionAir = transform.TransformDirection(moveDirectionAir);
  80.                 moveDirectionAir *= airSpeed;
  81.         }
  82.        
  83.         moveDirection.y -= gravity * Time.deltaTime;
  84.        
  85.         var controller : CharacterController = GetComponent(CharacterController);
  86.         var flags = controller.Move(moveDirection * Time.deltaTime);
  87.        
  88.         if(moveInAir) {
  89.                 controller.Move(moveDirectionAir * Time.deltaTime);
  90.         }
  91.        
  92.         grounded = (flags & CollisionFlags.CollidedBelow) != 0;
  93. }
  94.  
  95. @script RequireComponent(CharacterController)