Commit 96abdbcc authored by 16이진형's avatar 16이진형

flatland movement

parent 46410cc4
...@@ -40,25 +40,31 @@ public class FlatlandMovement : MonoBehaviour ...@@ -40,25 +40,31 @@ public class FlatlandMovement : MonoBehaviour
/// </summary> /// </summary>
List<float> pathVelocitys = new List<float>(); List<float> pathVelocitys = new List<float>();
protected void Update() protected void FixedUpdate()
{ {
if (isAutoMove) if (isAutoMove)
{ {
Vector3 tmp = new Vector3(transform.position.x,0,transform.position.z); Vector3 tmp = new Vector3(transform.position.x, 0, transform.position.z);
if (SpaceLength(nowDest, transform.position) < 0.1f || SpaceInnerPorduct(nowDest - tmp, v) < 0) if (SpaceLength(nowDest, transform.position) < 0.1f || SpaceInnerPorduct(nowDest - tmp, v) < 0)
{ {
//목적지 근접 or 넘어가면 //목적지 근접 or 넘어가면
Debug.Log("dest" + nowDest); Debug.Log("dest" + nowDest);
Debug.Log("position" + transform.position); Debug.Log("position" + transform.position);
//넘어간만큼 보정.
//TODO : 좀더 엄밀하게 수정 필요.
Vector3 nowpos = transform.position;
nowpos.x = nowDest.x;
nowpos.z = nowDest.z;
transform.position = nowpos;
if (dests.Count >= 1) if (dests.Count >= 1)
{ {
// 다음 목적지가 있을떄. // 다음 목적지가 있을떄.
MoveTo(dests[0], pathVelocitys[0]); //이동한다. NextMove(); //이동한다.
dests.RemoveAt(0);
pathVelocitys.RemoveAt(0);
} }
else else
{ {
...@@ -71,6 +77,11 @@ public class FlatlandMovement : MonoBehaviour ...@@ -71,6 +77,11 @@ public class FlatlandMovement : MonoBehaviour
} }
} }
} }
protected void Update()
{
}
/// <summary> /// <summary>
/// 시간축 y을 무시한 /// 시간축 y을 무시한
/// 거리 /// 거리
...@@ -97,40 +108,32 @@ public class FlatlandMovement : MonoBehaviour ...@@ -97,40 +108,32 @@ public class FlatlandMovement : MonoBehaviour
/// <summary> /// <summary>
/// 여러 위치를 거쳐서 이동합니다. /// 여러 위치를 거쳐서 이동합니다.
/// </summary> /// </summary>
/// <param name="path">목적지 리스트 0 번은 현재 위치 x y 가 공간</param> /// <param name="path">상대좌표 x z 가 공간</param>
/// <param name="v"> 경로별 속력 0번은 0.0f </param> /// <param name="v"> 경로별 속력 0번은 0.0f </param>
public bool MoveTo(List<Vector3> path, List<float> v) public bool MoveToRetivePosition(List<Vector3> path, List<float> v)
{ {
//Debug.Log("aa"); //Debug.Log("aa");
for (int i = 1; i < v.Count; i++) foreach(float a in v)
{ {
//Debug.Log(v[i]); if (a <= 0.0001f)
//속력 확인
if (v[1] < 0.0001f)
{ {
return false; return false;
} }
} }
if (path.Count >= 1)
if (path.Count >= 2)
{ {
dests = new List<Vector3>(); dests = new List<Vector3>();
//xy 공간 -> xz 공간 //상대좌표 -> 절대좌표
foreach(var a in path) foreach(var a in path)
{ {
dests.Add(new Vector3(transform.position.x + a.x, 0, transform.position.z + a.y)); dests.Add(new Vector3(transform.position.x + a.x, 0, transform.position.z + a.z));
} }
pathVelocitys = new List<float>(v); pathVelocitys = new List<float>(v);
//더미 제거
dests.RemoveAt(0);
pathVelocitys.RemoveAt(0);
} }
MoveTo(dests[0], pathVelocitys[0]); //start move
NextMove();
dests.RemoveAt(0);
pathVelocitys.RemoveAt(0);
return true; return true;
} }
...@@ -161,4 +164,13 @@ public class FlatlandMovement : MonoBehaviour ...@@ -161,4 +164,13 @@ public class FlatlandMovement : MonoBehaviour
return true; return true;
} }
private void NextMove()
{
MoveTo(dests[0], pathVelocitys[0]);
dests.RemoveAt(0);
pathVelocitys.RemoveAt(0);
}
} }
...@@ -123,7 +123,7 @@ public class PathRenderer : MonoBehaviour ...@@ -123,7 +123,7 @@ public class PathRenderer : MonoBehaviour
/// 0번은 내 위치 /// 0번은 내 위치
/// x y 가 공간 z 가 시간 /// x y 가 공간 z 가 시간
/// </summary> /// </summary>
public List<Vector3> PathPositions public List<Vector3> PathPositionsXY
{ {
get get
{ {
...@@ -131,6 +131,26 @@ public class PathRenderer : MonoBehaviour ...@@ -131,6 +131,26 @@ public class PathRenderer : MonoBehaviour
} }
} }
/// <summary> /// <summary>
/// 현재 설정된 경로를 반환.
/// 0번은 현재위치 //패트롤 고려
/// x z 가 공간 y 가 시간
/// </summary>
public List<Vector3> PathPositionsXZ
{
get
{
List<Vector3> list = new List<Vector3>();
foreach(var a in square.pathList)
{
//xy -> xz
list.Add(new Vector3(a.x, 0, a.y));
}
return list;
}
}
/// <summary>
/// 현재 설정된 경로의 속력을 반환. /// 현재 설정된 경로의 속력을 반환.
/// 0번은 0.0f /// 0번은 0.0f
/// </summary> /// </summary>
...@@ -138,7 +158,7 @@ public class PathRenderer : MonoBehaviour ...@@ -138,7 +158,7 @@ public class PathRenderer : MonoBehaviour
{ {
get get
{ {
return square.pathVelocity; return new List<float>(square.pathVelocity);
} }
} }
private void _InstantiatePathCollider(int n) private void _InstantiatePathCollider(int n)
......
...@@ -30,6 +30,8 @@ public class Planemovement : FlatlandMovement ...@@ -30,6 +30,8 @@ public class Planemovement : FlatlandMovement
// For physics calcs // For physics calcs
void FixedUpdate() void FixedUpdate()
{ {
base.FixedUpdate();
var prevup = transform.up; var prevup = transform.up;
var prevfor = transform.forward; var prevfor = transform.forward;
var prevorient = orientation; var prevorient = orientation;
......
...@@ -28,6 +28,8 @@ public class PlayerMovement : FlatlandMovement ...@@ -28,6 +28,8 @@ public class PlayerMovement : FlatlandMovement
// Update is called once per frame // Update is called once per frame
void FixedUpdate() void FixedUpdate()
{ {
base.FixedUpdate();
var prevup = transform.up; var prevup = transform.up;
var prevfor = transform.forward; var prevfor = transform.forward;
var prevorient = orientation; var prevorient = orientation;
......
...@@ -214,7 +214,18 @@ public class UIManager : MonoBehaviour ...@@ -214,7 +214,18 @@ public class UIManager : MonoBehaviour
public void PathStart() public void PathStart()
{ {
bool result; bool result;
result = levelManager.player.MoveTo(pathRenderer.PathPositions, pathRenderer.PathVelocitys); var positions = pathRenderer.PathPositionsXZ;
var velocitys = pathRenderer.PathVelocitys;
if(positions.Count<=1 || velocitys.Count <= 1)
{
return;
}
// remove dummy
positions.RemoveAt(0);
velocitys.RemoveAt(0);
result = levelManager.player.MoveToRetivePosition(positions,velocitys);
if (result) if (result)
{ {
......
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