Advertisement
Guest User

Untitled

a guest
Aug 14th, 2016
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1.         //IDLE STATE
  2.         if (state == PlayerState.Idle) {
  3.             if (Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.S) || Input.GetKeyDown (KeyCode.D) || Input.GetKeyDown (KeyCode.A)) {
  4.                 SetMovingState ();
  5.             }
  6.         }
  7.         //MOVING STATE
  8.         else if (state == PlayerState.Move) {
  9.             targetDirection.Set (0, 0, 0);
  10.             if (Input.GetKey (KeyCode.W)) {
  11.                 targetDirection.z += 1.0f;
  12.                 forwardSpeed = speed;
  13.             }
  14.             if (Input.GetKey (KeyCode.S)) {
  15.                 targetDirection.z -= 1.0f;
  16.                 forwardSpeed = speed;
  17.             }
  18.  
  19.             if (Input.GetKey (KeyCode.D)) {
  20.                 targetDirection.x += 1.0f;
  21.                 forwardSpeed = speed;
  22.             }
  23.             if (Input.GetKey (KeyCode.A)) {
  24.                 targetDirection.x -= 1.0f;
  25.                 forwardSpeed = speed;
  26.             }
  27.  
  28.             if (targetDirection.x == 0.0f && targetDirection.z == 0.0f) {
  29.                 SetDampingSate ();
  30.                 return;
  31.             }
  32.  
  33.             targetRotation = Quaternion.LookRotation (targetDirection);
  34.             rigidBody.MoveRotation (Quaternion.Slerp (transform.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime));
  35.             rigidBody.MovePosition (transform.position + transform.forward * forwardSpeed * Time.fixedDeltaTime);
  36.         }
  37.  
  38.         //DAMPING STATE
  39.         else if (state == PlayerState.Damping) {
  40.             if (Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.S) || Input.GetKeyDown (KeyCode.D) || Input.GetKeyDown (KeyCode.A)) {
  41.                 SetMovingState ();
  42.                 return;
  43.             }
  44.             forwardSpeed = Mathf.Lerp (forwardSpeed, 0, dampingSpeed * Time.fixedDeltaTime);
  45.             if (forwardSpeed <= 0.1f) {
  46.                 SetIdleState ();
  47.                 return;
  48.             }
  49.             rigidBody.MovePosition (transform.position + transform.forward * forwardSpeed * Time.fixedDeltaTime);
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement