Advertisement
Meee2

playerLook

Jun 11th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. float mainSpeed = 100.0f; //regular speed
  2. float shiftAdd = 250.0f; //multiplied by how long shift is held. Basically running
  3. float maxShift = 1000.0f; //Maximum speed when holdin gshift
  4. float camSens = 0.25f; //How sensitive it with mouse
  5. private Vector3 lastMouse = new Vector3(255, 255, 255); //kind of in the middle of the screen, rather than at the top (play)
  6. private float totalRun = 1.0f;
  7.  
  8. void Update()
  9. {
  10. lastMouse = Input.mousePosition - lastMouse;
  11. lastMouse = new Vector3(-lastMouse.y * camSens, lastMouse.x * camSens, 0);
  12. lastMouse = new Vector3(transform.eulerAngles.x + lastMouse.x, transform.eulerAngles.y + lastMouse.y, 0);
  13. transform.eulerAngles = lastMouse;
  14. lastMouse = Input.mousePosition;
  15. //Mouse camera angle done.
  16.  
  17. //Keyboard commands
  18. float f = 0.0f;
  19. Vector3 p = GetBaseInput();
  20. if (Input.GetKey(KeyCode.LeftShift))
  21. {
  22. totalRun += Time.deltaTime;
  23. p = p * totalRun * shiftAdd;
  24. p.x = Mathf.Clamp(p.x, -maxShift, maxShift);
  25. p.y = Mathf.Clamp(p.y, -maxShift, maxShift);
  26. p.z = Mathf.Clamp(p.z, -maxShift, maxShift);
  27. }
  28. else
  29. {
  30. totalRun = Mathf.Clamp(totalRun * 0.5f, 1f, 1000f);
  31. p = p * mainSpeed;
  32. }
  33.  
  34. p = p * Time.deltaTime;
  35. Vector3 newPosition = transform.position;
  36. if (Input.GetKey(KeyCode.Space))
  37. { //If player wants to move on X and Z axis only
  38. transform.Translate(p);
  39. newPosition.x = transform.position.x;
  40. newPosition.z = transform.position.z;
  41. transform.position = newPosition;
  42. }
  43. else
  44. {
  45. transform.Translate(p);
  46. }
  47.  
  48. }
  49.  
  50. private Vector3 GetBaseInput()
  51. { //returns the basic values, if it's 0 than it's not active.
  52. Vector3 p_Velocity = new Vector3();
  53. if (Input.GetKey(KeyCode.W))
  54. {
  55. p_Velocity += new Vector3(0, 0, 1);
  56. }
  57. if (Input.GetKey(KeyCode.S))
  58. {
  59. p_Velocity += new Vector3(0, 0, -1);
  60. }
  61. if (Input.GetKey(KeyCode.A))
  62. {
  63. p_Velocity += new Vector3(-1, 0, 0);
  64. }
  65. if (Input.GetKey(KeyCode.D))
  66. {
  67. p_Velocity += new Vector3(1, 0, 0);
  68. }
  69. return p_Velocity;
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement