balrougelive

Untitled

Nov 13th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. [RequireComponent (typeof (CharacterController))]
  8.  
  9.  
  10. public class PlayerController : MonoBehaviour
  11. {
  12. // Handling Variables:
  13.  
  14. public float rotationSpeed = 450; // Rotation Speed
  15. public float walkSpeed = 5; // Walking Speed
  16. public float runSpeed = 8; // Running Speed
  17.  
  18. // System Variable:
  19.  
  20. private CharacterController controller;
  21.  
  22. // Components of Movement:
  23.  
  24. private Quaternion targetRotation;
  25.  
  26. void Start()
  27. {
  28. controller = GetComponent<CharacterController>();
  29. }
  30.  
  31. void Update()
  32. {
  33. Vector3 input = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
  34.  
  35. if (input != Vector3.zero)
  36. {
  37. targetRotation = Quaternion.LookRotation(input);
  38. transform.rotation = Quaternion.LookRotation(input);
  39. transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle(transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeed * Time.deltaTime);
  40. }
  41.  
  42. // Setup the Vector3 motion:
  43.  
  44. Vector3 motion = input.normalized;
  45.  
  46. input *= (Mathf.Abs(input.x) == 1 && Mathf.Abs(input.z) == 1) ? .7f : 1;
  47. input *= (Input.GetButton("Run")) ? runSpeed : walkSpeed;
  48. motion += Vector3.up * -7;
  49.  
  50. controller.Move(motion * Time.deltaTime);
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment