Skip to content

Commit 00dc6a4

Browse files
committed
Waypoint monster following, still need comments
1 parent 2391128 commit 00dc6a4

File tree

5 files changed

+67
-16
lines changed

5 files changed

+67
-16
lines changed

Assets/MonsterController.cs

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@ public class MonsterController : MonoBehaviour
1010
public float minDistance = 0.25f;
1111
public float leaderDistance = 1.0f;
1212
public float speed = 1;
13-
public float rotationSpeed = 50;
1413
public GameObject bodyPrefab;
1514
public GameObject monsterHolder;
15+
public float waypointRate = 0.1f;
16+
public float waypointMax = 10;
1617

18+
private bool spawning = false;
1719
private float dis;
20+
private float prevWaypointTime = 0;
21+
private List<Vector3> waypoints = new List<Vector3>();
1822
private Transform curBodyPart;
1923
private Transform prevBodyPart;
2024

2125
// Start is called before the first frame update
2226
void Start()
2327
{
24-
bodyParts.Insert(0, leader);
28+
Debug.Log("START");
2529
}
2630

2731
// Update is called once per frame
@@ -33,12 +37,49 @@ void FixedUpdate()
3337
{
3438
AddBodyPart();
3539
}
40+
else
41+
{
42+
spawning = false;
43+
}
44+
}
45+
46+
private void MoveToNextWaypoint()
47+
{
48+
float curSpeed = speed;
49+
curBodyPart = bodyParts[0];
50+
51+
dis = Vector3.Distance(waypoints[0], curBodyPart.position);
52+
if (dis <= leaderDistance)
53+
{
54+
waypoints.RemoveAt(0);
55+
return;
56+
}
57+
58+
Vector3 newPos = waypoints[0];
59+
newPos.z = 0;
60+
61+
float T;
62+
T = Time.deltaTime * dis / leaderDistance * curSpeed;
63+
if (T > 0.5f)
64+
T = 0.5f;
65+
curBodyPart.position = Vector3.Slerp(curBodyPart.position, newPos, T);
3666
}
3767

3868
public void Move()
3969
{
4070
float curSpeed = speed;
4171

72+
if (Time.time > prevWaypointTime + waypointRate && waypoints.Count < waypointMax)
73+
{
74+
waypoints.Add(leader.position);
75+
prevWaypointTime = Time.time;
76+
}
77+
78+
if (bodyParts.Count > 0 && waypoints.Count > 0)
79+
{
80+
MoveToNextWaypoint();
81+
}
82+
4283
for (int i = 1; i < bodyParts.Count; i++)
4384
{
4485
curBodyPart = bodyParts[i];
@@ -54,7 +95,7 @@ public void Move()
5495
T = Time.deltaTime * dis / leaderDistance * curSpeed;
5596
else
5697
T = Time.deltaTime * dis / minDistance * curSpeed;
57-
98+
5899
if (T > 0.5f)
59100
T = 0.5f;
60101
curBodyPart.position = Vector3.Slerp(curBodyPart.position, newPos, T);
@@ -64,12 +105,17 @@ public void Move()
64105

65106
public void AddBodyPart()
66107
{
67-
if (bodyParts.Count - 1 < maxBodyParts)
108+
if (bodyParts.Count < maxBodyParts && !spawning)
68109
{
69-
GameObject part = Instantiate(bodyPrefab, bodyParts[bodyParts.Count - 1].position, bodyParts[bodyParts.Count - 1].rotation);
110+
GameObject part;
111+
if (bodyParts.Count == 0)
112+
part = Instantiate(bodyPrefab, leader.position, leader.rotation);
113+
else
114+
part = Instantiate(bodyPrefab, bodyParts[bodyParts.Count - 1].position, bodyParts[bodyParts.Count - 1].rotation);
70115
Transform newPart = part.transform;
71116
newPart.SetParent(monsterHolder.transform);
72117
bodyParts.Add(newPart);
118+
spawning = true;
73119
}
74120
}
75121
}

Assets/_Project/Materials/sky.mat

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ Material:
2626
m_LightmapFlags: 4
2727
m_EnableInstancingVariants: 0
2828
m_DoubleSidedGI: 0
29-
m_CustomRenderQueue: 2000
29+
m_CustomRenderQueue: 3000
3030
stringTagMap:
31-
RenderType: Opaque
32-
disabledShaderPasses: []
31+
RenderType: Transparent
32+
disabledShaderPasses:
33+
- SHADOWCASTER
3334
m_SavedProperties:
3435
serializedVersion: 3
3536
m_TexEnvs:
@@ -84,7 +85,7 @@ Material:
8485
- _Cull: 2
8586
- _Cutoff: 0.5
8687
- _DetailNormalMapScale: 1
87-
- _DstBlend: 0
88+
- _DstBlend: 10
8889
- _EnvironmentReflections: 1
8990
- _GlossMapScale: 1
9091
- _Glossiness: 0.5
@@ -98,11 +99,11 @@ Material:
9899
- _Smoothness: 0
99100
- _SmoothnessTextureChannel: 0
100101
- _SpecularHighlights: 1
101-
- _SrcBlend: 1
102-
- _Surface: 0
102+
- _SrcBlend: 5
103+
- _Surface: 1
103104
- _UVSec: 0
104105
- _WorkflowMode: 1
105-
- _ZWrite: 1
106+
- _ZWrite: 0
106107
m_Colors:
107108
- _BaseColor: {r: 0.28627452, g: 0.78431374, b: 0.85490197, a: 1}
108109
- _Color: {r: 0.24313726, g: 0.09019608, b: 0.5372549, a: 1}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:60c77b652ec07ec267dce4ee88710751e43c9be2e8148e85b80767246081da15
3-
size 31864
2+
oid sha256:ab330ace5af6d72cc120e02a8fda53e117df3c9488592d9577b127e3a0f2c0ae
3+
size 31882
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:33f3fd2902ea894d4b9252ff93ffdcb86c2d931900e6507f0f06b1ac1652f014
2+
oid sha256:8dc0fde4e989836d733575dd70c23cbf1b6915a448d293e8d867dd315b5822a0
33
size 116727

Assets/_Project/Scenes/tally-viz.unity

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ PrefabInstance:
583583
m_Modification:
584584
m_TransformParent: {fileID: 0}
585585
m_Modifications:
586+
- target: {fileID: 4060703217083337034, guid: ecec1fc7bdc6441a691ca908dfadc8b4, type: 3}
587+
propertyPath: rotationSpeed
588+
value: 1
589+
objectReference: {fileID: 0}
586590
- target: {fileID: 7489948669748588920, guid: ecec1fc7bdc6441a691ca908dfadc8b4, type: 3}
587591
propertyPath: m_LocalPosition.x
588592
value: 0
@@ -650,7 +654,7 @@ GameObject:
650654
m_Icon: {fileID: 0}
651655
m_NavMeshLayer: 0
652656
m_StaticEditorFlags: 0
653-
m_IsActive: 1
657+
m_IsActive: 0
654658
--- !u!95 &1339374948
655659
Animator:
656660
serializedVersion: 3

0 commit comments

Comments
 (0)