alaskajohn

Very Simple Avatar Controller

Jul 9th, 2014
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1.     public float movementSpeed = 0.1f;
  2.     public float jumpSpeed = 10.0f;
  3.     private bool isJumping = false;
  4.     private bool isFalling = false;
  5.  
  6.     // Get Input and Move player
  7.     void getInput()
  8.     {
  9.         float moveX = Input.GetAxis ("Horizontal") * movementSpeed;
  10.         float moveZ = Input.GetAxis ("Vertical") * movementSpeed;
  11.        
  12.         transform.Translate(moveX, 0, moveZ);
  13.        
  14.         if ((Input.GetButtonDown("Jump")) && (isJumping == false) && (isFalling == false))
  15.         {
  16.             rigidbody.velocity = new Vector3(0,jumpSpeed,0);
  17.             isJumping = true;
  18.         }
  19.        
  20.         if ((rigidbody.velocity.y < -0.1f) && isJumping)
  21.         {
  22.             isJumping = false;
  23.             isFalling = true;
  24.         }
  25.        
  26.         if ((Mathf.Abs(rigidbody.velocity.y) < 0.1f) && isFalling )
  27.         {
  28.             isFalling = false;
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment