Commit 2588e633 authored by 16이진형's avatar 16이진형

auto move only one path

parent 746a831e
......@@ -12,20 +12,153 @@ public class FlatlandMovement : MonoBehaviour
protected int cnt = 0;
protected double beta = 0.5f; // v/c
protected MatrixBuilder<double> M = Matrix<double>.Build;
protected VectorBuilder<double> V = Vector<double>.Build;
public Vector3 alpha = new Vector3(0.1f, 0.0f, 0.0f); // proper acceleration
public Vector3 v;
public Vector3 orientation;
public LevelManager Levelmanager;
public LevelManager levelManager;
public double gamma = 1.0f;
public double time = 0.0f;
// Start is called before the first frame update
public GameObject theobject;
protected MatrixBuilder<double> M = Matrix<double>.Build;
protected VectorBuilder<double> V = Vector<double>.Build;
// 마우스로 이동할때 하용하는 변수들.
bool isAutoMove = false;
Vector3 nowDest;
/// <summary>
/// 앞으로 남은 경로들.
/// </summary>
List<Vector3> paths = new List<Vector3>();
/// <summary>
/// 앞으로 남은 목적지 속력
/// </summary>
List<float> pathVelocitys = new List<float>();
protected void Update()
{
if (isAutoMove)
{
Vector3 tmp = new Vector3(transform.position.x,0,transform.position.z);
if (SpaceLength(nowDest, transform.position) < 0.1f || SpaceInnerPorduct(nowDest - tmp, v) < 0)
{
//목적지 근접 or 넘어가면
Debug.Log("dest" + nowDest);
Debug.Log("position" + transform.position);
if (paths.Count >= 1)
{
// 다음 목적지가 있을떄.
MoveTo(paths[0], pathVelocitys[0]); //이동한다.
paths.RemoveAt(0);
pathVelocitys.RemoveAt(0);
}
else
{
//다음목적지 없을때
v = Vector3.zero;
nowDest = Vector3.zero;
isAutoMove = false;
}
}
}
}
/// <summary>
/// 시간축 y을 무시한
/// 거리
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
protected float SpaceLength(Vector3 a, Vector3 b)
{
return Mathf.Sqrt((a.x - b.x) * (a.x - b.x) + (a.z - b.z) * (a.z - b.z));
}
/// <summary>
/// 시간축 y을 무시한
/// 내적
/// </summary>
/// <param name="a">xy가 공간</param>
/// <param name="b">xz가 공간</param>
/// <returns></returns>
protected float SpaceInnerPorduct(Vector3 a, Vector3 b)
{
return a.x * b.x + a.z * b.z;
}
/// <summary>
/// 여러 위치를 거쳐서 이동합니다.
/// </summary>
/// <param name="path">목적지 리스트 0 번은 현재 위치 x y 가 공간</param>
/// <param name="v"> 경로별 속력 0번은 0.0f </param>
public bool MoveTo(List<Vector3> path, List<float> v)
{
//Debug.Log("aa");
for (int i = 1; i < v.Count; i++)
{
//Debug.Log(v[i]);
//속력 확인
if (v[1] < 0.0001f)
{
return false;
}
}
if (path.Count >= 2)
{
paths = new List<Vector3>();
//xy 공간 -> xz 공간
foreach(var a in path)
{
paths.Add(new Vector3(a.x, 0, a.y));
}
pathVelocitys = new List<float>(v);
//더미 제거
paths.RemoveAt(0);
pathVelocitys.RemoveAt(0);
}
MoveTo(paths[0], pathVelocitys[0]);
paths.RemoveAt(0);
pathVelocitys.RemoveAt(0);
return true;
}
/// <summary>
/// 목적지로 바로 이동합니다.
/// </summary>
/// <param name="path">목적지 x z 가 공간</param>
/// <param name="v">속력</param>
private bool MoveTo(Vector3 path, float v)
{
Debug.Log("bb");
Debug.Log(path);
if (v < 0.0001f)
{
//v가 0일때.
return false;
}
//속도와 목적지 설정.
Vector3 tmp = path;
Debug.Log("move vector: " + tmp);
tmp.y = 0;
this.v = tmp.normalized * v * (float)Constants.c;
Debug.Log("v : "+ this.v);
this.nowDest = path + new Vector3(transform.position.x,0,transform.position.z);
isAutoMove = true;
return true;
}
}
......@@ -113,6 +113,34 @@ public class PathRenderer : MonoBehaviour
}
}
public void PathClear()
{
_ResetPaths();
}
/// <summary>
/// 현재 설정된 경로를 반환.
/// 0번은 내 위치
/// x y 가 공간 z 가 시간
/// </summary>
public List<Vector3> PathPositions
{
get
{
return square.pathList;
}
}
/// <summary>
/// 현재 설정된 경로의 속력을 반환.
/// 0번은 0.0f
/// </summary>
public List<float> PathVelocitys
{
get
{
return square.pathVelocity;
}
}
private void _InstantiatePathCollider(int n)
{
var _pathCollider = Instantiate(PathColliderPrefab, transform);
......
......@@ -22,6 +22,10 @@ public class Planemovement : FlatlandMovement
}
// Update is called once per frame
void Update()
{
base.Update();
}
// For physics calcs
void FixedUpdate()
......@@ -29,7 +33,7 @@ public class Planemovement : FlatlandMovement
var prevup = transform.up;
var prevfor = transform.forward;
var prevorient = orientation;
transform.Translate((float)Constants.c * Vector3.up * Time.fixedDeltaTime * (float)Levelmanager.player.gamma, Space.World); // move up by 1 second
transform.Translate((float)Constants.c * Vector3.up * Time.fixedDeltaTime * (float)levelManager.player.gamma, Space.World); // move up by 1 second
cnt++;
if (cnt % 480 == 0)
......@@ -66,7 +70,7 @@ public class Planemovement : FlatlandMovement
v = finaldeltav;
}
if ((Levelmanager.player.transform.position - transform.position).magnitude < 1f)
if ((levelManager.player.transform.position - transform.position).magnitude < 1f)
{
toggle = true;
}
......@@ -82,7 +86,7 @@ public class Planemovement : FlatlandMovement
if(grabbed)
{
v = Levelmanager.player.v;
v = levelManager.player.v;
Debug.Log("being grabbed");
}
else
......@@ -94,7 +98,7 @@ public class Planemovement : FlatlandMovement
gamma = Constants.Gamma(v.magnitude);
transform.Translate(v * Time.fixedDeltaTime * (float)Levelmanager.player.gamma, Space.World);
transform.Translate(v * Time.fixedDeltaTime * (float)levelManager.player.gamma, Space.World);
var vt = v + (float)Constants.c * Vector3.up;
......@@ -119,7 +123,7 @@ public class Planemovement : FlatlandMovement
transform.localScale = new Vector3(1.0f, 1.0f, (float)gamma); // scale x' axis
time += Time.fixedDeltaTime * (float)(Levelmanager.player.gamma / gamma);
time += Time.fixedDeltaTime * (float)(levelManager.player.gamma / gamma);
}
public void OnCollisionStaychild(Collision collision)
......@@ -135,7 +139,7 @@ public class Planemovement : FlatlandMovement
Debug.Log("hit!");
if (Mathf.Abs((float)(otherclock.GetTime() - time)) <= 1.0f)
{
Levelmanager.winstate = true;
levelManager.winstate = true;
}
}
}
......
......@@ -20,6 +20,11 @@ public class PlayerMovement : FlatlandMovement
alpha = new Vector3(0.0f, 0.0f, 0.0f);
}
void Update()
{
base.Update();
}
// Update is called once per frame
void FixedUpdate()
{
......
......@@ -26,7 +26,9 @@ public class UIManager : MonoBehaviour
//public Text clock2time;
public Text wintext;
public GameObject _pathUI;
public LevelManager Levelmanager;
public LevelManager levelManager;
public PathRenderer pathRenderer;
private int prevSelectPathNum = -1;
private Text pathName;
......@@ -54,10 +56,10 @@ public class UIManager : MonoBehaviour
// Update is called once per frame
void Update()
{
mytime.text = Levelmanager.player.time.ToString() + " s";
mytime.text = levelManager.player.time.ToString() + " s";
//clock1time.text = clock1.GetTime().ToString() + " s";
//clock2time.text = clock2.GetTime().ToString() + " s";
if(Levelmanager.winstate)
if(levelManager.winstate)
{
wintext.gameObject.SetActive(true);
}
......@@ -142,42 +144,44 @@ public class UIManager : MonoBehaviour
sliderflag = 0;
}
//player movement
if(Input.GetKeyDown("w"))
{
var tmp = accelslider.GetLogScaleValue();
Levelmanager.player.alpha += new Vector3(0, 0, tmp);
levelManager.player.alpha += new Vector3(0, 0, tmp);
}
else if(Input.GetKeyDown("a"))
{
var tmp = accelslider.GetLogScaleValue();
Levelmanager.player.alpha += new Vector3(-tmp, 0, 0);
levelManager.player.alpha += new Vector3(-tmp, 0, 0);
}
else if(Input.GetKeyDown("s"))
{
var tmp = accelslider.GetLogScaleValue();
Levelmanager.player.alpha += new Vector3(0, 0, -tmp);
levelManager.player.alpha += new Vector3(0, 0, -tmp);
}
else if(Input.GetKeyDown("d"))
{
var tmp = accelslider.GetLogScaleValue();
Levelmanager.player.alpha += new Vector3(tmp, 0, 0);
levelManager.player.alpha += new Vector3(tmp, 0, 0);
}
if (Input.GetKeyUp("w"))
{
Levelmanager.player.alpha -= new Vector3(0, 0, Levelmanager.player.alpha.z);
levelManager.player.alpha -= new Vector3(0, 0, levelManager.player.alpha.z);
}
else if (Input.GetKeyUp("a"))
{
Levelmanager.player.alpha -= new Vector3(Levelmanager.player.alpha.x, 0, 0);
levelManager.player.alpha -= new Vector3(levelManager.player.alpha.x, 0, 0);
}
else if (Input.GetKeyUp("s"))
{
Levelmanager.player.alpha -= new Vector3(0, 0, Levelmanager.player.alpha.z);
levelManager.player.alpha -= new Vector3(0, 0, levelManager.player.alpha.z);
}
else if (Input.GetKeyUp("d"))
{
Levelmanager.player.alpha -= new Vector3(Levelmanager.player.alpha.x, 0, 0);
levelManager.player.alpha -= new Vector3(levelManager.player.alpha.x, 0, 0);
}
}
......@@ -204,4 +208,18 @@ public class UIManager : MonoBehaviour
velocityslider.UpdateValuebyVelocity(square.GetPathVelocity(pathNum));
}
/// <summary>
/// 현재 지정된 path를 시작합니다.
/// </summary>
public void PathStart()
{
bool result;
result = levelManager.player.MoveTo(pathRenderer.PathPositions, pathRenderer.PathVelocitys);
if (result)
{
pathRenderer.PathClear();
}
}
}
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