Advertisement
Guest User

Untitled

a guest
May 30th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. void ApplyMovementAndRotation ()
  2.         {
  3.            
  4.                 Vector3 pos = Input.mousePosition;
  5.  
  6.                 float x = -Mathf.Clamp ((Screen.width * 0.5f - pos.x) / (Screen.width * screenArea), -1f, 1f);
  7.                 float y = -Mathf.Clamp ((Screen.height * 0.5f - pos.y) / (Screen.height * screenArea), -1f, 1f);
  8.  
  9.                 Vector2 vec = new Vector2 (x, y);
  10.  
  11.                 float mag = vec.magnitude;
  12.                 if (mag > 1f)
  13.                         vec *= 1.0f / mag;
  14.  
  15.                 mInput = Vector2.Lerp (mInput, vec, Mathf.Clamp01 (Time.deltaTime * responsiveness));
  16.                 mTurn = Vector2.Lerp (mTurn, vec - mInput, Mathf.Clamp01 (Time.deltaTime * turnSensitivity));
  17.  
  18.                 mTrans.localPosition = new Vector3 (mInput.x * movementDistance.x, mInput.y * movementDistance.y, 10);
  19.                
  20.                         mTrans.localRotation = Quaternion.Euler (-mTurn.y * turnDegrees.x,
  21.                                                      mTurn.x * turnDegrees.y,
  22.                                                      -mTurn.x * turnDegrees.z);
  23.                
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement