Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- [RequireComponent(typeof(PlayerMotor))]
- public class PlayerController : MonoBehaviour{
- [SerializeField]
- private float speed = 5f;
- [SerializeField]
- private float LookSensitivity = 3f;
- //Caching
- private PlayerMotor motor;
- void Start ()
- {
- motor = GetComponent<PlayerMotor>();
- }
- void Update ()
- {
- //Calculate movement velocity as a 3D vector
- float _xMov = Input.GetAxis("Horizontal");
- float _zMov = Input.GetAxis("Vertical");
- Vector3 _movHorizontal = transform.right * _xMov;
- Vector3 _movVertical = transform.forward * _zMov;
- // Final movement vector
- Vector3 _velocity = (_movHorizontal + _movVertical) * speed;
- //Apply movement
- motor.Move(_velocity);
- //Calculate rotation as a 3D vector (turning around)
- float _xRot = Input.GetAxisRaw("Mouse X");
- Vector3 _rotation = new Vector3(0f, _xRot, 0f) * LookSensitivity;
- //Apply rotation
- motor.Rotate(_rotation);
- //Calculate rotation as a 3D vector (turning around)
- float _yRot = Input.GetAxisRaw("Mouse Y");
- Vector3 _cameraRotation = new Vector3(0f, _yRot, 0f) * LookSensitivity;
- //Apply rotation
- motor.RotateCamera(_cameraRotation);
- }
- }
Add Comment
Please, Sign In to add comment