Advertisement
DirtyGamingUK

FPS Script

Jan 6th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. public class FirstPersonScript : MonoBehaviour {
  2.  
  3.     //PublicVariables //PublicDeclerations
  4.     public float MouseSensitivity = 7.0f;
  5.     public float zMovementspeed = 8.0f;
  6.     public float xMovementspeed = 9.0f;
  7.     public float PovRange = 110.0f;
  8.     public float RotationY = 0;
  9.    
  10.     void Start () {
  11.    
  12.         Screen.lockCursor = true;
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void Update () {
  17.  
  18.  
  19.     //Rotation
  20.     //Variables // Declerations
  21.         float RotationX = Input.GetAxis ("Mouse X") * MouseSensitivity;
  22.     //Callback
  23.         transform.Rotate (0, RotationX, 0);
  24.         RotationY -= Input.GetAxis ("Mouse Y") * MouseSensitivity;
  25.         RotationY = Mathf.Clamp (RotationY, -PovRange, PovRange);
  26.         Camera.main.transform.localRotation = Quaternion.Euler (RotationY, 0, 0);
  27.  
  28.     //Movement
  29.     //Variables // Declerations
  30.         float zAxispeed = Input.GetAxis ("Vertical") * zMovementspeed;
  31.         float xAxispeed = Input.GetAxis ("Horizontal") * xMovementspeed;
  32.         Vector3 zSpeed = new Vector3 (xAxispeed, 0, zAxispeed);
  33.         CharacterController CharControl = GetComponent<CharacterController>();
  34.    
  35.     //Callback
  36.         zSpeed = transform.rotation * zSpeed;
  37.         CharControl.SimpleMove( zSpeed );
  38.    
  39.     }
  40.  
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement