Commit 6ffdbed0 authored by 16이진형's avatar 16이진형

auto move multi path

parent 2588e633
...@@ -32,9 +32,9 @@ public class FlatlandMovement : MonoBehaviour ...@@ -32,9 +32,9 @@ public class FlatlandMovement : MonoBehaviour
Vector3 nowDest; Vector3 nowDest;
/// <summary> /// <summary>
/// 앞으로 남은 경로들. /// 앞으로 남은 목적지들.
/// </summary> /// </summary>
List<Vector3> paths = new List<Vector3>(); List<Vector3> dests = new List<Vector3>();
/// <summary> /// <summary>
/// 앞으로 남은 목적지 속력 /// 앞으로 남은 목적지 속력
/// </summary> /// </summary>
...@@ -52,11 +52,11 @@ public class FlatlandMovement : MonoBehaviour ...@@ -52,11 +52,11 @@ public class FlatlandMovement : MonoBehaviour
Debug.Log("dest" + nowDest); Debug.Log("dest" + nowDest);
Debug.Log("position" + transform.position); Debug.Log("position" + transform.position);
if (paths.Count >= 1) if (dests.Count >= 1)
{ {
// 다음 목적지가 있을떄. // 다음 목적지가 있을떄.
MoveTo(paths[0], pathVelocitys[0]); //이동한다. MoveTo(dests[0], pathVelocitys[0]); //이동한다.
paths.RemoveAt(0); dests.RemoveAt(0);
pathVelocitys.RemoveAt(0); pathVelocitys.RemoveAt(0);
} }
...@@ -114,23 +114,22 @@ public class FlatlandMovement : MonoBehaviour ...@@ -114,23 +114,22 @@ public class FlatlandMovement : MonoBehaviour
if (path.Count >= 2) if (path.Count >= 2)
{ {
paths = new List<Vector3>(); dests = new List<Vector3>();
//xy 공간 -> xz 공간 //xy 공간 -> xz 공간
foreach(var a in path) foreach(var a in path)
{ {
paths.Add(new Vector3(a.x, 0, a.y)); dests.Add(new Vector3(transform.position.x + a.x, 0, transform.position.z + a.y));
} }
pathVelocitys = new List<float>(v); pathVelocitys = new List<float>(v);
//더미 제거 //더미 제거
paths.RemoveAt(0); dests.RemoveAt(0);
pathVelocitys.RemoveAt(0); pathVelocitys.RemoveAt(0);
} }
MoveTo(paths[0], pathVelocitys[0]); MoveTo(dests[0], pathVelocitys[0]);
paths.RemoveAt(0); dests.RemoveAt(0);
pathVelocitys.RemoveAt(0); pathVelocitys.RemoveAt(0);
return true; return true;
...@@ -140,22 +139,22 @@ public class FlatlandMovement : MonoBehaviour ...@@ -140,22 +139,22 @@ public class FlatlandMovement : MonoBehaviour
/// </summary> /// </summary>
/// <param name="path">목적지 x z 가 공간</param> /// <param name="path">목적지 x z 가 공간</param>
/// <param name="v">속력</param> /// <param name="v">속력</param>
private bool MoveTo(Vector3 path, float v) private bool MoveTo(Vector3 dest, float v)
{ {
Debug.Log("bb"); Debug.Log("bb");
Debug.Log(path); Debug.Log(dest);
if (v < 0.0001f) if (v < 0.0001f)
{ {
//v가 0일때. //v가 0일때.
return false; return false;
} }
//속도와 목적지 설정. //속도와 목적지 설정.
Vector3 tmp = path; Vector3 tmp = dest-transform.position;
Debug.Log("move vector: " + tmp); Debug.Log("move vector: " + tmp);
tmp.y = 0; tmp.y = 0;
this.v = tmp.normalized * v * (float)Constants.c; this.v = tmp.normalized * v * (float)Constants.c;
Debug.Log("v : "+ this.v); Debug.Log("v : "+ this.v);
this.nowDest = path + new Vector3(transform.position.x,0,transform.position.z); this.nowDest = dest;
isAutoMove = true; isAutoMove = true;
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment