Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Start of Movement script
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Movement : MonoBehaviour
- {
- [SerializeField] bool grounded = false;
- [SerializeField] CharacterController controller;
- [SerializeField] float speed = 10f;//ground speed
- [SerializeField] float jHeight = 1.5f;//jump height
- [SerializeField] Vector3 crouch = new Vector3(1f, 0.5f, 1f);
- [SerializeField] float crspd = 4.5f;
- [SerializeField] float sia = 5.7325f;//speed in air
- float ground_dist;
- float x, y, z;
- Vector3 velocity;
- [SerializeField] float gravity = -9.81f;
- // Update is called once per frame
- void Update()
- {
- if(grounded && velocity.y<0)
- {
- velocity.y = 0;
- }
- x = Input.GetAxis("Horizontal");
- y = Input.GetAxis("Jump");
- z = Input.GetAxis("Vertical");
- ground_dist = 1f + 0.08f;
- if (Physics.Raycast(transform.position, -transform.up, out _, ground_dist))
- {
- grounded = true;
- }
- else
- {
- grounded = false;
- }
- Vector3 move = transform.right * x + transform.forward * z;
- if(Input.GetKey(KeyCode.LeftControl) && z==1f && grounded)//Sprint
- {
- controller.Move(speed * 1.5f * Time.deltaTime * move);
- }
- if(grounded)
- {
- controller.Move(speed * Time.deltaTime * move);
- }
- if(!grounded)
- {
- controller.Move(sia * Time.deltaTime * move);
- }
- if (y==1f && grounded)
- {
- velocity.y = Mathf.Sqrt(jHeight * -2f * gravity);
- }
- velocity.y += gravity * Time.deltaTime;
- controller.Move(velocity * Time.deltaTime);
- }
- }
- //End of movement script
- //Start of vision script
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Vision : MonoBehaviour
- {
- [SerializeField] private float sens = 100f;
- [SerializeField] Transform player;
- float xrotation = 0f;
- // Start is called before the first frame update
- void Start()
- {
- Cursor.lockState = CursorLockMode.Locked;
- }
- // Update is called once per frame
- void Update()
- {
- float x = Input.GetAxis("Mouse X") * sens * Time.deltaTime;
- float y = Input.GetAxis("Mouse Y") * sens * Time.deltaTime;
- xrotation -= y;
- xrotation = Mathf.Clamp(xrotation, -90f, 90f);
- transform.localRotation = Quaternion.Euler(xrotation, 0f, 0f);
- player.Rotate(Vector3.up * x);
- }
- }
- //End of vision code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement