Last active
April 15, 2019 14:55
-
-
Save peterkimzz/a02f718166ea71d040a669e67cf75b35 to your computer and use it in GitHub Desktop.
Revisions
-
peterkimzz revised this gist
Apr 15, 2019 . 1 changed file with 0 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,10 +7,7 @@ public class PlayerController : MonoBehaviour // 이동속도 [SerializeField] private float moveSpeed; private bool isMoving = false; // 화면 위에서 클릭하는 마우스 좌표 private Vector3 mouseHitPos; @@ -19,10 +16,6 @@ public class PlayerController : MonoBehaviour [SerializeField] private CharacterController cc; void Update() { TryMove(); -
peterkimzz renamed this gist
Apr 15, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
peterkimzz revised this gist
Apr 15, 2019 . 1 changed file with 28 additions and 32 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,21 +9,19 @@ public class PlayerController : MonoBehaviour private float moveSpeed; // 이동 코루틴 private bool isMoving = false; private IEnumerator coroutine; // 화면 위에서 클릭하는 마우스 좌표 private Vector3 mouseHitPos; // 필요한 컴포넌트 [SerializeField] private CharacterController cc; // 애니메이터 [SerializeField] private Animator anim; void Update() { @@ -33,42 +31,40 @@ void Update() private void TryMove() { // 마우스 우클릭 if (Input.GetMouseButton(0)) { RaycastHit mouseHit; // 제대로 된 Ground 태그를 눌러야만 이동을 시킬거임 if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out mouseHit)) { if (mouseHit.transform.tag == "Ground") { mouseHitPos = mouseHit.point; isMoving = true; } } } if (isMoving) Move(); } private void Move() { if (Vector3.Distance(transform.position, mouseHitPos) == 0f) { isMoving = false; return; } Vector3 dir = mouseHitPos - transform.position; Vector3 dirXZ = new Vector3(dir.x, 0f, dir.z); Vector3 targetPos = transform.position + dirXZ; Vector3 framePos = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime); Vector3 moveDir = (framePos - transform.position) + Physics.gravity; cc.Move(moveDir); } } -
peterkimzz renamed this gist
Apr 14, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
peterkimzz revised this gist
Apr 14, 2019 . 1 changed file with 33 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,36 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { // 이동속도 [SerializeField] private float moveSpeed; // 이동 코루틴 private bool isMoveCoroutineRunning = false; private IEnumerator coroutine; // 화면 위에서 클릭하는 마우스 좌표 private RaycastHit mouseHit; // 필요한 컴포넌트 private CapsuleCollider myCapsuleCollider; private Rigidbody myRigidBody; void Start() { myCapsuleCollider = transform.GetComponent<CapsuleCollider>(); myRigidBody = transform.GetComponent<Rigidbody>(); } void Update() { TryMove(); } private void TryMove() { // 마우스 우클릭 if (Input.GetMouseButton(1)) @@ -41,4 +68,7 @@ private IEnumerator MoveCoroutine() } isMoveCoroutineRunning = false; } } -
peterkimzz created this gist
Apr 14, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ void Update() { TryMove(); } private void TryMove() { // 마우스 우클릭 if (Input.GetMouseButton(1)) { // 제대로 된 Ground 태그를 눌러야만 이동을 시킬거임 if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out mouseHit)) { if (mouseHit.transform.tag == "Ground") Move(); } } } private void Move() { if (isMoveCoroutineRunning) StopCoroutine(coroutine); coroutine = MoveCoroutine(); StartCoroutine(coroutine); } private IEnumerator MoveCoroutine() { // 플레이어는 지면 위에서만 움직일거기 때문에 y값은 지면 맨 위 + 플레이어의 높이만큼으로 고정 Vector3 DestinationPos = mouseHit.point; DestinationPos.y = DestinationPos.y + myCapsuleCollider.bounds.extents.y; Vector3 velocity = (DestinationPos - transform.position).normalized * moveSpeed; float distance = Vector3.Distance(transform.position, DestinationPos); while (distance > 0.2f) { isMoveCoroutineRunning = true; myRigidBody.MovePosition(transform.position + velocity * Time.deltaTime); distance = Vector3.Distance(transform.position, DestinationPos); yield return null; } isMoveCoroutineRunning = false; }