Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [RequireComponent(typeof(CharacterController))]
- public class MovementHero : MonoBehaviour
- {
- [Header("Скорость персонажа")]
- [Range(0.5f, 35)]
- public float SpeedMovement = 1f;
- [Header("Чувствительность мыши")]
- [Range(0.1f, 1f)]
- public float Sensivity = 1f;
- [Header("Минимальный угол просмотра")]
- [Range(0f, -120f)]
- public float YMinLimit = -45f;
- [Header("Максимальный угол просмотра")]
- [Range(120f, 0f)]
- public float YMaxLimit = 45f;
- [Header("Сила гравитации")]
- public float GlobalGravity = 9.81f;
- [Header("Максимальная дистанция от земли")]
- public float MaxDistance = 0f;
- CharacterController movementController;
- Transform mainCamera;
- float xRotate, yRotate = 0f;
- private void Start()
- {
- movementController = gameObject.GetComponent<CharacterController>();
- mainCamera = Camera.main.transform;
- // Lock the cursor
- Cursor.lockState = CursorLockMode.Locked;
- Cursor.visible = false;
- }
- private void FixedUpdate()
- {
- float horizontal = Input.GetAxis("Horizontal");
- float vertical = Input.GetAxis("Vertical");
- Vector3 direction = new Vector3(horizontal, 0, vertical);
- movementController.Move(direction * SpeedMovement * Time.fixedDeltaTime);
- }
- private void Update()
- {
- Vector3 mousePos = Input.mousePosition;
- float kefAngel = ((Screen.width - mousePos.x) / Screen.width);
- kefAngel = kefAngel < 0 ? kefAngel * 2 : kefAngel;
- kefAngel = Mathf.Clamp(kefAngel, -1, 1); // Normalize
- xRotate = mousePos.y * Sensivity * 0.15f;
- xRotate = Mathf.Clamp(xRotate, YMinLimit, YMaxLimit);
- yRotate = 360 * kefAngel * Sensivity;
- transform.rotation = Quaternion.Euler(0, -yRotate, 0);
- mainCamera.rotation = Quaternion.Euler(-xRotate, yRotate, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement