Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ColdShot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
15박보승
ColdShot
Commits
7d136bc8
Commit
7d136bc8
authored
Jan 26, 2020
by
15박보승
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debug on WorldToIndex (Div by zero). SetPath implemented.
parent
9eb0b10d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
4 deletions
+58
-4
Pathfinding.unity
Assets/Scenes/Pathfinding.unity
+6
-1
Enemy.cs
Assets/Scripts/Enemy.cs
+37
-0
NodalPathfinding2D.cs
Assets/Scripts/NodalPathfinding/NodalPathfinding2D.cs
+2
-2
NodalPathfinding2DAgent.cs
Assets/Scripts/NodalPathfinding/NodalPathfinding2DAgent.cs
+13
-1
No files found.
Assets/Scenes/Pathfinding.unity
View file @
7d136bc8
...
...
@@ -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
...
...
Assets/Scripts/Enemy.cs
View file @
7d136bc8
...
...
@@ -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
++)
{
...
...
Assets/Scripts/NodalPathfinding/NodalPathfinding2D.cs
View file @
7d136bc8
...
...
@@ -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
;
...
...
Assets/Scripts/NodalPathfinding/NodalPathfinding2DAgent.cs
View file @
7d136bc8
...
...
@@ -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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment