Commit 7d136bc8 authored by 15박보승's avatar 15박보승

Debug on WorldToIndex (Div by zero). SetPath implemented.

parent 9eb0b10d
......@@ -261,7 +261,7 @@ MonoBehaviour:
bounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 10, y: 10, z: 0}
pointInterval: 1
pointInterval: 0.314
agentRadius: 0.1
blockMask:
serializedVersion: 2
......@@ -871,6 +871,11 @@ MonoBehaviour:
_health: 0
eyesightRange: 5
eyesightDegree: 89
roamingPath:
- {x: 8.72, y: 5.15, z: 0}
- {x: 7.2, y: 8.25, z: 0}
- {x: 1.8, y: 7.3, z: 0}
- {x: 4.8, y: 6.78, z: 0}
blockEyesightMask:
serializedVersion: 2
m_Bits: 256
......
......@@ -11,9 +11,28 @@ public class Enemy : Actor
[Range(0, 360)]
public int eyesightDegree = 60;
[SerializeField]
private List<Vector3> roamingPath;
[SerializeField]
private LayerMask blockEyesightMask;
#if UNITY_EDITOR
private void OnDrawGizmos()
{
if (roamingPath.Count < 1)
return;
/*
Gizmos.color = Color.white;
Gizmos.DrawLine(transform.position, roamingPath[0]);
for (int i = 0; i < roamingPath.Count; i++)
{
Gizmos.DrawLine(roamingPath[i], roamingPath[(i + 1) % roamingPath.Count]);
}
*/
}
#endif
protected override void Start()
{
base.Start();
......@@ -21,11 +40,14 @@ public class Enemy : Actor
mf = GetComponentInChildren<MeshFilter>();
eyesightMesh = new Mesh();
mf.mesh = eyesightMesh;
agent.SetPath(roamingPath);
}
private void Update()
{
UpdateEyesightMesh();
if (agent.path.Count < 1)
agent.SetPath(roamingPath);
}
private void UpdateEyesightMesh()
......@@ -34,6 +56,7 @@ public class Enemy : Actor
List<int> indices = new List<int>();
vertices.Add(Vector3.zero);
/*
for (int i = -eyesightDegree / 2; i <= eyesightDegree / 2; i++)
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, Quaternion.Euler(0, 0, i) * transform.up, eyesightRange, blockEyesightMask);
......@@ -46,6 +69,20 @@ public class Enemy : Actor
vertices.Add(quat * (hit.point - new Vector2(transform.position.x, transform.position.y)));
}
}
*/
for (int i = -eyesightDegree / 2; i <= eyesightDegree / 2; i++)
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, Quaternion.Euler(0, 0, i) * transform.up, eyesightRange, blockEyesightMask);
if (hit.collider == null)
vertices.Add((Quaternion.Euler(0, 0, i) * Vector3.up) * eyesightRange);
else
{
Quaternion quat = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, -transform.rotation.eulerAngles.z);
vertices.Add(quat * (hit.point - new Vector2(transform.position.x, transform.position.y)));
}
}
for (int i = 0; i < vertices.Count - 2; i++)
{
......
......@@ -107,7 +107,7 @@ namespace BS
}
#endif
private void Start()
private void Awake()
{
if (!isBaked)
BakeNodes();
......@@ -547,7 +547,7 @@ namespace BS
foreach (var adj in adjs)
{
float score = Vector2.Dot((IndexToWorld(adj) - position).normalized, direction.normalized) / (IndexToWorld(adj) - position).magnitude;
float score = Vector2.Dot((IndexToWorld(adj) - position).normalized, direction.normalized) / ((IndexToWorld(adj) - position).magnitude + 1);
if (max < score)
{
index = adj;
......
......@@ -83,6 +83,18 @@ namespace BS {
}
}
public void SetPath(List<Vector3> path)
{
this.destination = path[path.Count - 1];
List<Vector3> newPath = new List<Vector3>();
newPath.Add(transform.position);
foreach (var next in path)
{
newPath.AddRange(pathFinder.GetPathAstar(newPath[newPath.Count - 1], next));
}
this.path = newPath;
}
public void Move(Vector2 direction)
{
......@@ -101,7 +113,7 @@ namespace BS {
{
path.RemoveAt(0);
}
else if (path.Count > 1 && Vector2.Distance(transform.position, path[0]) < pathFinder.pointInterval / 2)
else if (path.Count > 1 && Vector2.Distance(transform.position, path[0]) < pathFinder.pointInterval / 10)
{
path.RemoveAt(0);
}
......
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