diff --git a/Assets/Scripts/Stage/Controller/PlayerController.cs b/Assets/Scripts/Stage/Controller/PlayerController.cs index d67d9a6..364b5d4 100644 --- a/Assets/Scripts/Stage/Controller/PlayerController.cs +++ b/Assets/Scripts/Stage/Controller/PlayerController.cs @@ -5,25 +5,26 @@ using UnityEngine; public class PlayerController : MonoBehaviour { - [SerializeField] private GameObject _playerObj; + [SerializeField] private MinigameController _minigameController; - private float _turnSpeed = 40; - private float _moveSpeed = 5; + private bool _isPushed = false; //Move values - private float _camRotate = 0; - private float _moveHorizontal = 0; - private float _moveVertical = 0; - private Vector3 _moveDir; - private bool _isJumping = false; + + //private Rigidbody _rigidBody; + + private PlayerMove _playerMove; + + public bool IsBlock { get; private set; } void Start() { + _playerMove = GetComponent(); EventBus.Instance.Subscribe(OnGetMinigamePoint); } @@ -36,21 +37,17 @@ public class PlayerController : MonoBehaviour return; } - _camRotate = Input.GetAxis("Mouse X"); + _playerMove.Rotate(Input.GetAxis("Mouse X")); + + var _moveHorizontal = Input.GetAxis("Horizontal"); + var _moveVertical = Input.GetAxis("Vertical"); - CamRotate(); - - _moveHorizontal = Input.GetAxis("Horizontal"); - _moveVertical = Input.GetAxis("Vertical"); - - Move(); - - if(!_isJumping && Input.GetKeyDown(KeyCode.Space)) + _playerMove.Move(_moveHorizontal, _moveVertical); + + if(Input.GetKeyDown(KeyCode.Space)) { - _isJumping = true; - GetComponent().AddForce(Vector3.up * 300, ForceMode.Acceleration); + _playerMove.Jump(); } - if (!_isPushed && Input.GetKeyDown(KeyCode.Q)) { @@ -65,19 +62,6 @@ public class PlayerController : MonoBehaviour } } - private void CamRotate() - { - _playerObj.transform.Rotate(Vector3.up * _turnSpeed * Time.deltaTime * _camRotate); - } - - private void Move() - { - _moveDir = (_playerObj.transform.forward * _moveVertical) + (_playerObj.transform.right * _moveHorizontal); - transform.Translate(_moveDir.normalized * Time.deltaTime * _moveSpeed); - } - - - private void PushStart() { _isPushed = true; @@ -110,14 +94,6 @@ public class PlayerController : MonoBehaviour } #region Collision - private void OnCollisionEnter(Collision collision) - { - //º®ÀÌ ¾Æ´Ñ ¹°Ã¼(¿ÀºêÁ§Æ®, ¹Ù´Ú) - if (collision.gameObject.layer == LayerMask.NameToLayer("Floor")) - { - _isJumping = false; - } - } private void OnCollisionExit(Collision collision) { diff --git a/Assets/Scripts/Stage/Controller/PlayerMove.cs b/Assets/Scripts/Stage/Controller/PlayerMove.cs new file mode 100644 index 0000000..fd02a2a --- /dev/null +++ b/Assets/Scripts/Stage/Controller/PlayerMove.cs @@ -0,0 +1,36 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerMove : MonoBehaviour +{ + [SerializeField] private Transform _playerObj; + [SerializeField] private CharacterController _characterController; + + private Vector3 _moveDir; + + public void Jump() + { + if (_characterController.isGrounded == true) + { + _moveDir.y = Constants.JUMP_FORCE; + } + } + + public void Move(float horizontal, float vertical) + { + var dir = (_playerObj.transform.forward * vertical) + (_playerObj.transform.right * horizontal); + _moveDir.x = dir.x; + _moveDir.z = dir.z; + if (_characterController.isGrounded == false) + { + _moveDir.y += Physics.gravity.y * Time.deltaTime; + } + _characterController.Move(_moveDir * Constants.MOVE_SPEED * Time.deltaTime); + } + + public void Rotate(float rotate) + { + _playerObj.transform.Rotate(Vector3.up * Constants.CAM_TURN_SPEED * Time.deltaTime * rotate); + } +} diff --git a/Assets/Scripts/Stage/Controller/PlayerMove.cs.meta b/Assets/Scripts/Stage/Controller/PlayerMove.cs.meta new file mode 100644 index 0000000..17472d6 --- /dev/null +++ b/Assets/Scripts/Stage/Controller/PlayerMove.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 957ce77a8667f9045a2fc0c3416b0c91 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: